Add source bundle validation and inspection
This commit is contained in:
70
internal/bundle/discover_test.go
Normal file
70
internal/bundle/discover_test.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package bundle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/distributor/internal/storage"
|
||||
"gitea.maximumdirect.net/eric/distributor/internal/storage/fake"
|
||||
)
|
||||
|
||||
func TestDiscoverFindsBundlesInDeterministicOrder(t *testing.T) {
|
||||
backend := fake.New()
|
||||
addBundle(t, backend, "z/daily")
|
||||
addBundle(t, backend, "a/daily")
|
||||
|
||||
bundles, err := Discover(context.Background(), backend, "")
|
||||
if err != nil {
|
||||
t.Fatalf("Discover() error = %v", err)
|
||||
}
|
||||
var paths []string
|
||||
for _, sourceBundle := range bundles {
|
||||
paths = append(paths, sourceBundle.RootRelativePath)
|
||||
}
|
||||
want := []string{"a/daily", "z/daily"}
|
||||
if !reflect.DeepEqual(paths, want) {
|
||||
t.Fatalf("paths = %v, want %v", paths, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverFindsRootBundle(t *testing.T) {
|
||||
backend := validFakeBundle(t)
|
||||
bundles, err := Discover(context.Background(), backend, "")
|
||||
if err != nil {
|
||||
t.Fatalf("Discover() error = %v", err)
|
||||
}
|
||||
if got, want := len(bundles), 1; got != want {
|
||||
t.Fatalf("bundle count = %d, want %d", got, want)
|
||||
}
|
||||
if bundles[0].RootRelativePath != "" {
|
||||
t.Fatalf("root = %q, want empty", bundles[0].RootRelativePath)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverRejectsNestedManifests(t *testing.T) {
|
||||
backend := fake.New()
|
||||
addBundle(t, backend, "daily")
|
||||
addBundle(t, backend, "daily/nested")
|
||||
|
||||
_, err := Discover(context.Background(), backend, "")
|
||||
assertErrorContains(t, err, "nested manifest")
|
||||
}
|
||||
|
||||
func addBundle(t *testing.T, backend *fake.Backend, root string) {
|
||||
t.Helper()
|
||||
writeFakeFile(t, backend, joinTestPath(root, "manifest.json"), string(readFixture(t, "testdata/valid_bundle/manifest.json")))
|
||||
writeFakeFile(t, backend, joinTestPath(root, "report.md"), string(readFixture(t, "testdata/valid_bundle/report.md")))
|
||||
writeFakeFile(t, backend, joinTestPath(root, "summary.txt"), string(readFixture(t, "testdata/valid_bundle/summary.txt")))
|
||||
}
|
||||
|
||||
func joinTestPath(root, file string) string {
|
||||
if root == "" {
|
||||
return file
|
||||
}
|
||||
joined, err := storage.Join(root, file)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return joined
|
||||
}
|
||||
Reference in New Issue
Block a user