package deploy import ( "os" "testing" "go.yaml.in/yaml/v4" ) type composeDocument struct { Services map[string]composeService `yaml:"services"` Volumes map[string]any `yaml:"volumes"` } type composeService struct { Command []string `yaml:"command"` Volumes []string `yaml:"volumes"` DependsOn any `yaml:"depends_on"` } func TestLocalRedisIsExplicitlyEphemeral(t *testing.T) { document := loadComposeDocument(t) redis, ok := document.Services["redis"] if !ok { t.Fatal("docker-compose.yml has no redis service") } if value, ok := commandFlag(redis.Command, "--appendonly"); !ok || value != "no" { t.Fatalf("redis --appendonly = %q, %t; want no", value, ok) } if value, ok := commandFlag(redis.Command, "--save"); !ok || value != "" { t.Fatalf("redis --save = %q, %t; want empty schedule", value, ok) } if len(redis.Volumes) != 0 { t.Fatalf("redis volumes = %v; want no persistent mount", redis.Volumes) } if _, exists := document.Volumes["redis-data"]; exists { t.Fatal("docker-compose.yml still declares redis-data") } } func TestLocalGatewaysDoNotDependOnControlPlaneStorage(t *testing.T) { document := loadComposeDocument(t) for _, name := range []string{"gateway-a", "gateway-b"} { gateway, ok := document.Services[name] if !ok { t.Fatalf("docker-compose.yml has no %s service", name) } for _, storage := range []string{"postgres", "redis"} { if composeDependsOn(gateway.DependsOn, storage) { t.Errorf("%s depends on %s; gateway startup must be storage-independent", name, storage) } } } } func loadComposeDocument(t *testing.T) composeDocument { t.Helper() payload, err := os.ReadFile("docker-compose.yml") if err != nil { t.Fatalf("read docker-compose.yml: %v", err) } var document composeDocument if err := yaml.Unmarshal(payload, &document); err != nil { t.Fatalf("parse docker-compose.yml: %v", err) } return document } func composeDependsOn(value any, service string) bool { switch dependencies := value.(type) { case map[string]any: _, exists := dependencies[service] return exists case []any: for _, dependency := range dependencies { if dependency == service { return true } } } return false } func commandFlag(command []string, name string) (string, bool) { for index := 0; index+1 < len(command); index++ { if command[index] == name { return command[index+1], true } } return "", false }