57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
package common_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"src.opensuse.org/autogits/common"
|
|
)
|
|
|
|
func TestManifestSubdirAssignments(t *testing.T) {
|
|
tests := []struct {
|
|
Name string
|
|
ManifestContent string
|
|
Packages []string
|
|
ManifestLocations []string
|
|
}{
|
|
{
|
|
Name: "empty manifest",
|
|
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "boost", "NodeJS"},
|
|
ManifestLocations: []string{"atom", "blarg", "Foobar", "X-Ray", "boost", "NodeJS"},
|
|
},
|
|
{
|
|
Name: "only few subdirs manifest",
|
|
ManifestContent: "subdirectories:\n - a\n - b",
|
|
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS"},
|
|
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "b/Boost", "NodeJS"},
|
|
},
|
|
{
|
|
Name: "multilayer subdirs manifest",
|
|
ManifestContent: "subdirectories:\n - a\n - b\n - libs/boo",
|
|
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS"},
|
|
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "libs/boo/Boost", "NodeJS"},
|
|
},
|
|
{
|
|
Name: "multilayer subdirs manifest with trailing /",
|
|
ManifestContent: "subdirectories:\n - a\n - b\n - libs/boo/\n - somedir/Node/",
|
|
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS", "foobar/node2"},
|
|
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "libs/boo/Boost", "somedir/Node/NodeJS", "somedir/Node/node2"},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
m, err := common.ParseManifestFile([]byte(test.ManifestContent))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
for i, pkg := range test.Packages {
|
|
expected := test.ManifestLocations[i]
|
|
if l := m.SubdirForPackage(pkg); l != expected {
|
|
t.Error("Expected:", expected, "but got:", l)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|