Compare commits

..

No commits in common. "ce4194e5b2708b2fa3683add10d6d0695a09a9a2" and "e0bc2a34b08bc37c53ade8cc9d2a216ea87f993d" have entirely different histories.

4 changed files with 21 additions and 41 deletions

View file

@ -33,7 +33,7 @@ func TestPublishAppRequiresDeliveryConfigBeforeCheckout(t *testing.T) {
bootstrapConfigPath = "test-config.yaml" bootstrapConfigPath = "test-config.yaml"
bootstrapPublishAppFrom = "app-checkout" bootstrapPublishAppFrom = "app-checkout"
loadPublishAppConfig = func(string) (config.Config, error) { loadPublishAppConfig = func(string) (config.Config, error) {
return config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}, Delivery: config.DeliveryConfig{AppName: "legacy-app"}}, nil return config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}}, nil
} }
ensurePublishAppCheckoutClean = func(string) error { ensurePublishAppCheckoutClean = func(string) error {
t.Fatal("publish inspected the checkout before validating delivery config") t.Fatal("publish inspected the checkout before validating delivery config")

View file

@ -80,7 +80,7 @@ func TestGeneratedDeliveryIsGenericAndUsesSafePreviewCleanupContract(t *testing.
func TestGenerateAppDeliveryRequiresCompleteConfig(t *testing.T) { func TestGenerateAppDeliveryRequiresCompleteConfig(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
err := GenerateAppDelivery(dir, config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}, Delivery: config.DeliveryConfig{AppName: "legacy-app"}}) err := GenerateAppDelivery(dir, config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}})
if err == nil || !strings.Contains(err.Error(), "delivery appName") { if err == nil || !strings.Contains(err.Error(), "delivery appName") {
t.Fatalf("GenerateAppDelivery() error = %v, want incomplete delivery error", err) t.Fatalf("GenerateAppDelivery() error = %v, want incomplete delivery error", err)
} }
@ -710,16 +710,6 @@ 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}}}}, 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 { if err := (Runner{Config: cfg, RegisterWebhook: true}).Run(); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -28,33 +28,23 @@ func validConfig(t *testing.T) Config {
} }
} }
func TestResolveDeliveryStates(t *testing.T) { func TestResolveAcceptsPlatformOnlyConfig(t *testing.T) {
platformOnly := validConfig(t) cfg := validConfig(t)
platformOnly.Delivery = DeliveryConfig{} cfg.Delivery.AppName = ""
partialLegacy := platformOnly cfg.Delivery.AppRepoURL = ""
partialLegacy.Delivery.AppName = "legacy-app" cfg.Delivery.AppRepoRef = ""
cfg.Delivery.ProductionBranch = ""
for _, test := range []struct { cfg.Delivery.ImageRepository = ""
name string cfg.Delivery.BuildOutputDirectory = ""
cfg Config cfg.Delivery.BuildConfiguration = ""
configured bool cfg.Delivery.WebhookHostname = ""
}{ cfg.Delivery.WebhookPath = ""
{name: "absent", cfg: platformOnly}, resolved, err := Resolve(cfg)
{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 { if err != nil {
t.Fatalf("Resolve() error = %v", err) t.Fatalf("Resolve() rejected platform-only config: %v", err)
} }
if resolved.Delivery.Configured() != test.configured { if resolved.Delivery.Configured() {
t.Fatalf("Configured() = %t, want %t", resolved.Delivery.Configured(), test.configured) t.Fatal("Resolve() invented delivery settings for a platform-only config")
}
if !test.configured && resolved.Delivery.AppRepoRef != "" {
t.Fatal("Resolve() defaulted delivery configuration treated as absent")
}
})
} }
} }

View file

@ -40,9 +40,9 @@ type DeliveryConfig struct {
WebhookPath string `yaml:"webhookPath"` WebhookPath string `yaml:"webhookPath"`
} }
// Configured reports whether the non-default app-delivery settings are complete. // Configured reports whether the configuration contains any app-delivery setting.
func (c DeliveryConfig) Configured() bool { func (c DeliveryConfig) Configured() bool {
return c.AppName != "" && c.AppRepoURL != "" && c.ProductionBranch != "" && c.ImageRepository != "" return c.AppName != "" || c.AppRepoURL != "" || c.AppRepoRef != "" || c.ProductionBranch != "" || c.ImageRepository != "" || c.BuildOutputDirectory != "" || c.BuildConfiguration != "" || c.WebhookHostname != "" || c.WebhookPath != ""
} }
func (c DeliveryConfig) WebhookURL() string { func (c DeliveryConfig) WebhookURL() string {