A collision is two places, not two spellings
checkResources compared paths as written, so ${dir:state}/server.env —
the same characters in every module, a different directory in each —
refused the first two placed modules that met. Paths are placed before
they are compared, under the default root, which keeps every real
collision: distinct modules' places are distinct under any one root,
and a module stating another's placed root is caught because a pathless
directory now owns its placed path in the comparison too.
This commit is contained in:
@@ -221,6 +221,28 @@ func TestPlaceIsValidatedAtTheManifest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTwoModulesPlacedRootsAreNoCollision(t *testing.T) {
|
||||
a := Manifest{Module: "gitea", Resources: []map[string]any{
|
||||
{"id": "state", "type": "directory", "place": "."},
|
||||
{"id": "env", "type": "file", "path": "${dir:state}/server.env", "content": ""},
|
||||
}}
|
||||
b := Manifest{Module: "nextcloud", Resources: []map[string]any{
|
||||
{"id": "state", "type": "directory", "place": "."},
|
||||
{"id": "env", "type": "file", "path": "${dir:state}/server.env", "content": ""},
|
||||
}}
|
||||
if got := checkResources([]Manifest{a, b}); len(got) != 0 {
|
||||
t.Fatalf("alike templates are different places; got %v", got)
|
||||
}
|
||||
// And the real collision is still caught: a module stating another's placed root.
|
||||
c := Manifest{Module: "squatter", Resources: []map[string]any{
|
||||
{"id": "nest", "type": "directory", "path": "/var/lib/gitea"},
|
||||
}}
|
||||
got := checkResources([]Manifest{a, c})
|
||||
if len(got) != 1 || !strings.Contains(got[0], `"/var/lib/gitea"`) {
|
||||
t.Fatalf("a stated path on a placed root collides; got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func shallowCopy(resource map[string]any) map[string]any {
|
||||
copied := map[string]any{}
|
||||
for k, v := range resource {
|
||||
|
||||
Reference in New Issue
Block a user