Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions internal/service/deploy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,7 @@ func (s *Service) Deploy(ctx context.Context, options Options) (Result, error) {
wranglerCfg.CompatibilityDate = options.CompatDate
}
if len(options.Var) > 0 {
if wranglerCfg.Vars == nil {
wranglerCfg.Vars = map[string]string{}
}
for _, item := range options.Var {
key, value, ok := splitPair(item)
if ok {
wranglerCfg.Vars[key] = value
project.Bindings.Vars[key] = value
}
}
applyVars(&project, &wranglerCfg, options.Var)
}
for _, route := range options.Route {
wranglerCfg.Routes = config.UpsertRoute(wranglerCfg.Routes, config.WranglerRoute{Pattern: route})
Expand Down Expand Up @@ -227,6 +218,26 @@ func splitPair(value string) (string, string, bool) {
return "", "", false
}

func applyVars(project *config.Project, wranglerCfg *config.WranglerConfig, vars []string) {
if len(vars) == 0 {
return
}
if wranglerCfg.Vars == nil {
wranglerCfg.Vars = map[string]string{}
}
if project.Bindings.Vars == nil {
project.Bindings.Vars = map[string]string{}
}
for _, item := range vars {
key, value, ok := splitPair(item)
if !ok {
continue
}
wranglerCfg.Vars[key] = value
project.Bindings.Vars[key] = value
}
}

func canFallbackToPlainDeploy(options Options, err error) bool {
if options.UploadOnly || options.Message == "" {
return false
Expand Down
23 changes: 22 additions & 1 deletion internal/service/deploy/service_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
package deploy

import "testing"
import (
"testing"

"github.com/paolo/flare-edge-cli/internal/domain/config"
)

func TestSplitPair(t *testing.T) {
key, value, ok := splitPair("FOO=bar")
if !ok || key != "FOO" || value != "bar" {
t.Fatalf("unexpected split result: %q %q %v", key, value, ok)
}
}

func TestApplyVarsInitializesNilMaps(t *testing.T) {
project := config.Project{}
wranglerCfg := config.WranglerConfig{}

applyVars(&project, &wranglerCfg, []string{"ORCHESTRATOR_URL=https://example.com", "BROKEN"})

if got := wranglerCfg.Vars["ORCHESTRATOR_URL"]; got != "https://example.com" {
t.Fatalf("unexpected wrangler var value: %q", got)
}
if got := project.Bindings.Vars["ORCHESTRATOR_URL"]; got != "https://example.com" {
t.Fatalf("unexpected project var value: %q", got)
}
if _, exists := wranglerCfg.Vars["BROKEN"]; exists {
t.Fatalf("invalid var entry should be ignored")
}
}
Loading