Every held thing carries what a take compares: for a found container its image and the image's date, the networks it is on and the other containers on each, its mounts and published ports, beside the declared image (and its date once pulled), ports and volumes, with the downgrade decided when both dates are known; for a found file whether the declared content differs and how, as lines lost and lines new. A resource whose target moved keeps the former target on record as an orphan, so the next apply removes the container or file the host wrote under the old name (issue 097). Every apply reports the strays: containers the mesh neither wrote nor holds.
30 lines
1.4 KiB
Go
30 lines
1.4 KiB
Go
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)
|
|
}
|
|
}
|