diff --git a/cmd/bootstrap_test.go b/cmd/bootstrap_test.go index 7596e90..a4a9309 100644 --- a/cmd/bootstrap_test.go +++ b/cmd/bootstrap_test.go @@ -33,7 +33,7 @@ func TestPublishAppRequiresDeliveryConfigBeforeCheckout(t *testing.T) { bootstrapConfigPath = "test-config.yaml" bootstrapPublishAppFrom = "app-checkout" loadPublishAppConfig = func(string) (config.Config, error) { - return config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}}, nil + return config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}, Delivery: config.DeliveryConfig{AppName: "legacy-app"}}, nil } ensurePublishAppCheckoutClean = func(string) error { t.Fatal("publish inspected the checkout before validating delivery config") diff --git a/internal/bootstrap/bootstrap_test.go b/internal/bootstrap/bootstrap_test.go index 4957bdc..fb5b945 100644 --- a/internal/bootstrap/bootstrap_test.go +++ b/internal/bootstrap/bootstrap_test.go @@ -80,7 +80,7 @@ func TestGeneratedDeliveryIsGenericAndUsesSafePreviewCleanupContract(t *testing. func TestGenerateAppDeliveryRequiresCompleteConfig(t *testing.T) { dir := t.TempDir() - err := GenerateAppDelivery(dir, config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}}) + err := GenerateAppDelivery(dir, config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}, Delivery: config.DeliveryConfig{AppName: "legacy-app"}}) if err == nil || !strings.Contains(err.Error(), "delivery appName") { t.Fatalf("GenerateAppDelivery() error = %v, want incomplete delivery error", err) } @@ -710,6 +710,16 @@ func TestRunnerRegisterWebhookSkipsTemplateRevisions(t *testing.T) { Nodes: []config.TalosNode{{Name: "cp-01", VMID: 100, Role: "controlplane", Networks: []config.TalosNetwork{{IP: "192.168.45.3", CIDR: "192.168.45.0/28", Gateway: "192.168.45.1", VLANID: 45}, {IP: "192.168.45.18", CIDR: "192.168.45.16/28", VLANID: 451}}}}, }, } + partial := cfg + partial.Delivery.ImageRepository = "" + preflight = func(config.Config) error { + t.Fatal("webhook registration accepted incomplete delivery config") + return nil + } + if err := (Runner{Config: partial, RegisterWebhook: true}).Run(); err == nil || !strings.Contains(err.Error(), "imageRepository") { + t.Fatalf("webhook registration error = %v, want incomplete delivery error", err) + } + preflight = func(config.Config) error { return nil } if err := (Runner{Config: cfg, RegisterWebhook: true}).Run(); err != nil { t.Fatal(err) } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 4aaf816..85b8b30 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -28,23 +28,33 @@ func validConfig(t *testing.T) Config { } } -func TestResolveAcceptsPlatformOnlyConfig(t *testing.T) { - cfg := validConfig(t) - cfg.Delivery.AppName = "" - cfg.Delivery.AppRepoURL = "" - cfg.Delivery.AppRepoRef = "" - cfg.Delivery.ProductionBranch = "" - cfg.Delivery.ImageRepository = "" - cfg.Delivery.BuildOutputDirectory = "" - cfg.Delivery.BuildConfiguration = "" - cfg.Delivery.WebhookHostname = "" - cfg.Delivery.WebhookPath = "" - resolved, err := Resolve(cfg) - if err != nil { - t.Fatalf("Resolve() rejected platform-only config: %v", err) - } - if resolved.Delivery.Configured() { - t.Fatal("Resolve() invented delivery settings for a platform-only config") +func TestResolveDeliveryStates(t *testing.T) { + platformOnly := validConfig(t) + platformOnly.Delivery = DeliveryConfig{} + partialLegacy := platformOnly + partialLegacy.Delivery.AppName = "legacy-app" + + for _, test := range []struct { + name string + cfg Config + configured bool + }{ + {name: "absent", cfg: platformOnly}, + {name: "partial legacy", cfg: partialLegacy}, + {name: "complete", cfg: validConfig(t), configured: true}, + } { + t.Run(test.name, func(t *testing.T) { + resolved, err := Resolve(test.cfg) + if err != nil { + t.Fatalf("Resolve() error = %v", err) + } + if resolved.Delivery.Configured() != test.configured { + t.Fatalf("Configured() = %t, want %t", resolved.Delivery.Configured(), test.configured) + } + if !test.configured && resolved.Delivery.AppRepoRef != "" { + t.Fatal("Resolve() defaulted delivery configuration treated as absent") + } + }) } } diff --git a/internal/config/types.go b/internal/config/types.go index 63e1e33..e77bbaf 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -40,9 +40,9 @@ type DeliveryConfig struct { WebhookPath string `yaml:"webhookPath"` } -// Configured reports whether the configuration contains any app-delivery setting. +// Configured reports whether the non-default app-delivery settings are complete. func (c DeliveryConfig) Configured() bool { - return c.AppName != "" || c.AppRepoURL != "" || c.AppRepoRef != "" || c.ProductionBranch != "" || c.ImageRepository != "" || c.BuildOutputDirectory != "" || c.BuildConfiguration != "" || c.WebhookHostname != "" || c.WebhookPath != "" + return c.AppName != "" && c.AppRepoURL != "" && c.ProductionBranch != "" && c.ImageRepository != "" } func (c DeliveryConfig) WebhookURL() string {