package server import ( "os" "reflect" "testing" "gopkg.in/yaml.v3" ) func TestStandardComposeRunsLayaOnCPUAndKeepsOllamaOptional(t *testing.T) { data, err := os.ReadFile("../../../docker-compose.yml") if err != nil { t.Fatal(err) } var compose struct { Services map[string]struct { Image string `yaml:"image"` Build any `yaml:"build"` Environment map[string]string `yaml:"environment"` Profiles []string `yaml:"profiles"` } `yaml:"services"` } if err := yaml.Unmarshal(data, &compose); err != nil { t.Fatalf("parse docker-compose.yml: %v", err) } t.Run("laya is configured for CPU", func(t *testing.T) { laya, ok := compose.Services["laya"] if !ok { t.Fatal("standard Compose is missing the Laya service") } if laya.Image == "" && laya.Build == nil { t.Fatal("Laya service must declare an image or build") } if laya.Environment["LAYA_DEVICE"] != "cpu" { t.Errorf("Laya environment=%v; want LAYA_DEVICE=cpu", laya.Environment) } }) t.Run("Ollama is optional", func(t *testing.T) { ollama, ok := compose.Services["ollama"] if !ok { t.Fatal("optional summary Ollama service is missing") } if len(ollama.Profiles) == 0 { t.Errorf("Ollama has no Compose profile and would run in the standard stack") } }) } func TestProductionComposeUsesPublishedImagesAndPreservesRuntime(t *testing.T) { read := func(path string) map[string]any { t.Helper() data, err := os.ReadFile(path) if err != nil { t.Fatal(err) } var document map[string]any if err := yaml.Unmarshal(data, &document); err != nil { t.Fatal(err) } return document } standard := read("../../../docker-compose.yml") production := read("../../../docker-compose.prod.yml") services := production["services"].(map[string]any) names := map[string]string{"backend": "backend", "frontend": "frontend", "scraper": "scraper", "laya": "laya"} for name, raw := range services { service := raw.(map[string]any) if _, exists := service["build"]; exists { t.Errorf("%s still builds", name) } if service["pull_policy"] == "build" { t.Errorf("%s has build pull policy", name) } if suffix, ok := names[name]; ok { want := "gitea.anthonybouteiller.ovh/blomios/tradarr-" + suffix + ":${TRADARR_IMAGE_TAG:?TRADARR_IMAGE_TAG is required}" if service["image"] != want { t.Errorf("%s image=%v", name, service["image"]) } } original := standard["services"].(map[string]any)[name].(map[string]any) delete(original, "build") delete(original, "pull_policy") if _, ok := names[name]; ok { delete(original, "image") delete(service, "image") } if name == "backend" { if service["stop_grace_period"] != "5m" { t.Error("production shutdown grace lost") } delete(service, "stop_grace_period") } if !reflect.DeepEqual(original, service) { t.Errorf("%s runtime differs from standard Compose", name) } } if !reflect.DeepEqual(standard["volumes"], production["volumes"]) { t.Error("volumes differ") } }