package catalogue import ( "strings" "testing" ) // The paths a module's tree is taken from are the union its artifacts name, cleaned and sorted, and only when every // artifact names some (novox/hq ADR 0499 clause 2); a module with an artifact that names none, or with none at all, // keeps its directory's tree. func TestAModulesNamedPathsAreTheUnionWhenEveryArtifactNamesThem(t *testing.T) { m := Manifest{Module: "a", Build: &Build{Artifacts: []Artifact{ {Name: "lib", Kind: ArtifactPackage, Paths: []string{"src/", "package.json"}}, {Name: "tools", Kind: ArtifactBundle, Paths: []string{"./src", "tools"}}, }}} paths, every := m.NamedPaths() if !every || strings.Join(paths, ",") != "package.json,src,tools" { t.Fatalf("NamedPaths = %v, %v; want [package.json src tools], true", paths, every) } m.Build.Artifacts = append(m.Build.Artifacts, Artifact{Name: "img", Kind: ArtifactImage, From: "Dockerfile"}) if paths, every := m.NamedPaths(); every || paths != nil { t.Fatalf("a module with an artifact naming no path gave %v, %v", paths, every) } if paths, every := (Manifest{Module: "b"}).NamedPaths(); every || paths != nil { t.Fatalf("a module that builds nothing gave %v, %v", paths, every) } }