Test that a mounted source names and reads its manifest beside its files, before or after the mount
This commit is contained in:
@@ -182,3 +182,22 @@ func TestAMountedTreeIsAValidFS(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAMountedSourceNamesItsManifestBesideItsFiles(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
for name, c := range map[string]struct {
|
||||
src Source
|
||||
want string
|
||||
}{
|
||||
"an fs.FS": {FS(fstest.MapFS{}).Mounted("my.data"), "my/data/.fejkdata.json"},
|
||||
"a data path": {Dir(dir).Mounted("my.data"), filepath.ToSlash(filepath.Join(dir, ".fejkdata.json"))},
|
||||
} {
|
||||
if got := c.src.ManifestPath(); got != c.want {
|
||||
t.Errorf("%s: ManifestPath() = %q, want %q", name, got, c.want)
|
||||
}
|
||||
}
|
||||
m, err := FS(fstest.MapFS{ManifestFile: {Data: []byte(`{"namespace": "my.data"}`)}}).Mounted("my.data").Manifest()
|
||||
if err != nil || m.Namespace != "my.data" {
|
||||
t.Errorf("Manifest() after Mounted = %+v, %v, want the manifest read from beside the files", m, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,6 +597,18 @@ func indexEntry(s categorySite) datafiles.IndexEntry {
|
||||
return e
|
||||
}
|
||||
|
||||
func TestAMountedIndexedCategoryWithNoFileNamesTheManifestBesideItsFiles(t *testing.T) {
|
||||
f, err := New(WithDataFS(fstest.MapFS{
|
||||
".fejkdata.json": {Data: []byte(`{"index": {"my.gone": {"paths": [""]}}, "namespace": "my"}`)},
|
||||
}))
|
||||
if err != nil {
|
||||
t.Fatalf("New() = %v", err)
|
||||
}
|
||||
if _, err := f.Fake("my.gone"); err == nil || !strings.Contains(err.Error(), "my/.fejkdata.json indexes my.gone") {
|
||||
t.Fatalf(`Fake("my.gone") = %v, want the manifest named as my/.fejkdata.json`, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnIndexedCategoryWithNoFileNamesTheManifest(t *testing.T) {
|
||||
f, err := New(WithDataFS(fstest.MapFS{
|
||||
".fejkdata.json": {Data: []byte(`{"index": {"gone": {"paths": [""]}}}`)},
|
||||
|
||||
Reference in New Issue
Block a user