34 lines
1.3 KiB
Go
34 lines
1.3 KiB
Go
package delivery
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// The indexer's modules value carries each artifact's named paths (novox/hq ADR 0499; the lead's decision L8 of R4e):
|
|
// the checker tells from it whether a change touches lib's paths without reading a manifest. An older value has none.
|
|
func TestAModulesValueCarriesEachArtifactsNamedPaths(t *testing.T) {
|
|
m := Module{FP2: SourcePrefix2 + strings.Repeat("a", 64), Repository: "novox/mesh-sdk", Commit: "c",
|
|
ArtifactPaths: map[string][]string{"lib": {"package-lock.json", "package.json", "src", "test", "tsconfig.json"}}}
|
|
data, err := EncodeModule(m)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(data), `"paths":{"lib":[`) {
|
|
t.Fatalf("the value carries no paths: %s", data)
|
|
}
|
|
back, err := DecodeModule(data)
|
|
if err != nil || len(back.ArtifactPaths["lib"]) != 5 || back.ArtifactPaths["lib"][2] != "src" {
|
|
t.Fatalf("decoded %+v, %v", back.ArtifactPaths, err)
|
|
}
|
|
if old, err := DecodeModule([]byte(`{"v":1,"fp":"src1:x","repository":"a/b","commit":"c"}`)); err != nil || old.ArtifactPaths != nil {
|
|
t.Fatalf("an older value: %+v, %v", old, err)
|
|
}
|
|
for _, bad := range []map[string][]string{{"": {"src"}}, {"lib": {}}, {"lib": {"../x"}}, {"lib": {""}}} {
|
|
m.ArtifactPaths = bad
|
|
if _, err := EncodeModule(m); err == nil {
|
|
t.Errorf("%v was accepted", bad)
|
|
}
|
|
}
|
|
}
|