package appbackup import ( "os" "path/filepath" "reflect" "testing" ) // R-49 (D21 = B): the template's `backup.volumes` list — only `excluded`, only declared named volumes, never all of them. func TestR49_ExcludedDockerVolumes(t *testing.T) { dir := filepath.Join(t.TempDir(), "immich") os.MkdirAll(dir, 0o755) compose := filepath.Join(dir, "docker-compose.yml") os.WriteFile(compose, []byte("services:\n a:\n image: x\n volumes:\n - immich_ml_cache:/cache\n - immich_postgres_data:/db\nvolumes:\n immich_ml_cache:\n immich_postgres_data:\n"), 0o644) spec := &BackupSpec{Volumes: []VolumeSpec{ {Name: "immich_ml_cache", Class: ClassExcluded}, {Name: "no_such_volume", Class: ClassExcluded}, {Name: "immich_postgres_data", Class: ClassMandatory}, }} ex, ignored := ExcludedDockerVolumes(spec, compose) if !reflect.DeepEqual(ex, []string{"immich_immich_ml_cache"}) { t.Fatalf("excluded = %v, want [immich_immich_ml_cache] (project-prefixed like ResolveDockerVolumeNames)", ex) } if len(ignored) != 2 { t.Fatalf("ignored = %v, want the unknown name and the non-excluded class", ignored) } all := &BackupSpec{Volumes: []VolumeSpec{{Name: "immich_ml_cache", Class: ClassExcluded}, {Name: "immich_postgres_data", Class: ClassExcluded}}} if ex, ig := ExcludedDockerVolumes(all, compose); ex != nil || len(ig) == 0 { t.Fatalf("excluding EVERY named volume must be refused (a hollow unit), got %v / %v", ex, ig) } if ex, _ := ExcludedDockerVolumes(nil, compose); ex != nil { t.Fatal("no backup block → nothing excluded") } } // The new key never costs an app its bind classifications: a block whose only fault is a bad volume entry still // validates (ValidateBackupSpec does not read Volumes). func TestR49_AVolumeEntryNeverInvalidatesTheBlock(t *testing.T) { spec := &BackupSpec{HDD: []BindSpec{{Path: "appdata/immich", Class: ClassMandatory}}, Volumes: []VolumeSpec{{Name: "nonsense", Class: "bogus"}}} binds := []ComposeBind{{Root: RootHDD, RelPath: "appdata/immich"}} if err := ValidateBackupSpec(spec, binds); err != nil { t.Fatalf("a bad volume entry discarded the block: %v", err) } }