package store import "testing" // A resource whose target moves leaves what the host wrote under the old target on record as a // former one, undeclared by construction, so the next apply removes it (novox/hq issue 097, ADR 0163). func TestARecordWhoseTargetMovedKeepsTheFormerTargetToRemove(t *testing.T) { s := State{} s.Record(Applied{ID: "gitea.server", Type: "container", Target: "mesh-gitea", Origin: OriginDeclared}) s.Record(Applied{ID: "gitea.server", Type: "container", Target: "gitea", Origin: OriginDeclared}) if len(s.Resources) != 2 { t.Fatalf("a moved target produced %d record(s): %+v", len(s.Resources), s.Resources) } orphans := s.Orphans(map[string]bool{"gitea.server": true}, OriginDeclared) if len(orphans) != 1 || orphans[0].Target != "mesh-gitea" || !IsFormer(orphans[0].ID) { t.Fatalf("the former target is not an orphan to remove: %+v", orphans) } s.Forget(orphans[0].ID) if len(s.Resources) != 1 || s.Resources[0].Target != "gitea" { t.Fatalf("forgetting the former target touched the current one: %+v", s.Resources) } // The same target again is not a move; a carried record is not the host's to remove. s.Record(Applied{ID: "gitea.server", Type: "container", Target: "gitea", Origin: OriginDeclared}) s.Record(Applied{ID: "bundle", Type: "file", Target: "/a"}) s.Record(Applied{ID: "bundle", Type: "file", Target: "/b"}) if len(s.Resources) != 2 { t.Fatalf("an unmoved or carried record grew the list: %+v", s.Resources) } }