Merge pull request 'fix: tolerate partial delivery config' (#15) from fix/partial-delivery-reconcile into main
Reviewed-on: #15
This commit is contained in:
commit
ce4194e5b2
|
|
@ -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"}}, nil
|
return config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}, Delivery: config.DeliveryConfig{AppName: "legacy-app"}}, 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")
|
||||||
|
|
|
||||||
|
|
@ -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"}})
|
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") {
|
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,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}}}},
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,23 +28,33 @@ func validConfig(t *testing.T) Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveAcceptsPlatformOnlyConfig(t *testing.T) {
|
func TestResolveDeliveryStates(t *testing.T) {
|
||||||
cfg := validConfig(t)
|
platformOnly := validConfig(t)
|
||||||
cfg.Delivery.AppName = ""
|
platformOnly.Delivery = DeliveryConfig{}
|
||||||
cfg.Delivery.AppRepoURL = ""
|
partialLegacy := platformOnly
|
||||||
cfg.Delivery.AppRepoRef = ""
|
partialLegacy.Delivery.AppName = "legacy-app"
|
||||||
cfg.Delivery.ProductionBranch = ""
|
|
||||||
cfg.Delivery.ImageRepository = ""
|
for _, test := range []struct {
|
||||||
cfg.Delivery.BuildOutputDirectory = ""
|
name string
|
||||||
cfg.Delivery.BuildConfiguration = ""
|
cfg Config
|
||||||
cfg.Delivery.WebhookHostname = ""
|
configured bool
|
||||||
cfg.Delivery.WebhookPath = ""
|
}{
|
||||||
resolved, err := Resolve(cfg)
|
{name: "absent", cfg: platformOnly},
|
||||||
if err != nil {
|
{name: "partial legacy", cfg: partialLegacy},
|
||||||
t.Fatalf("Resolve() rejected platform-only config: %v", err)
|
{name: "complete", cfg: validConfig(t), configured: true},
|
||||||
}
|
} {
|
||||||
if resolved.Delivery.Configured() {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
t.Fatal("Resolve() invented delivery settings for a platform-only config")
|
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")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,9 @@ type DeliveryConfig struct {
|
||||||
WebhookPath string `yaml:"webhookPath"`
|
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 {
|
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 {
|
func (c DeliveryConfig) WebhookURL() string {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue