Test that WithDataFS refuses a nil module and a manifest's reads refuses a repeated module

This commit is contained in:
2026-10-10 13:28:42 +02:00
committed by Lillem4n
parent 949d2709da
commit 97ff2dfaa1
2 changed files with 11 additions and 17 deletions
+8
View File
@@ -1,6 +1,7 @@
package fejkdata package fejkdata
import ( import (
"io/fs"
"reflect" "reflect"
"slices" "slices"
"strings" "strings"
@@ -134,6 +135,13 @@ func TestWithDataFSLayersEachModuleOverTheOneBefore(t *testing.T) {
} }
} }
func TestWithDataFSRefusesANilModule(t *testing.T) {
var unset fs.FS
if _, err := New(WithDataFS(fstest.MapFS{}, unset)); err == nil || !strings.Contains(err.Error(), "WithDataFS module 2 is nil") {
t.Errorf("New(WithDataFS(fsys, nil)) = %v, want module 2 named nil", err)
}
}
func TestFakeIsSafeForConcurrentUse(t *testing.T) { func TestFakeIsSafeForConcurrentUse(t *testing.T) {
f, err := New(withShipped(), WithSeed(1)) f, err := New(withShipped(), WithSeed(1))
if err != nil { if err != nil {
+3 -17
View File
@@ -183,21 +183,6 @@ func shippedIndex(t *testing.T) map[string]datafiles.IndexEntry {
return index return index
} }
func TestEachShippedModuleNamesWhatItReads(t *testing.T) {
for _, m := range shippedModules(t) {
manifest, err := datafiles.FS(m.fsys).Manifest()
if err != nil {
t.Fatal(err)
}
if m.dir == "sv_SE" && !slices.Contains(manifest.Reads, "github.com/larvit/fejkdata/data/geo/SE") {
t.Errorf("sv_SE reads %v, want geo/SE among them", manifest.Reads)
}
if slices.Contains(manifest.Reads, m.importPath()) {
t.Errorf("%s reads %v, want itself left out", m.dir, manifest.Reads)
}
}
}
func TestEachShippedModuleRendersBesideTheModulesItReads(t *testing.T) { func TestEachShippedModuleRendersBesideTheModulesItReads(t *testing.T) {
modules := shippedModules(t) modules := shippedModules(t)
for _, m := range modules { for _, m := range modules {
@@ -439,8 +424,9 @@ func TestABrokenManifestFailsNewNamingEveryMistake(t *testing.T) {
`{"index": {"a": {"paths": ["", "x", "x"]}}}`: {`paths item 3 repeats "x"`}, `{"index": {"a": {"paths": ["", "x", "x"]}}}`: {`paths item 3 repeats "x"`},
`{"index": {"a": {"paths": [""], "parent": "b"}}}`: {`parent "b" names no entry`}, `{"index": {"a": {"paths": [""], "parent": "b"}}}`: {`parent "b" names no entry`},
`{"index": {"a": {"paths": [""], "reads": ["b"]}}}`: {`unknown key "reads"`}, `{"index": {"a": {"paths": [""], "reads": ["b"]}}}`: {`unknown key "reads"`},
`{"reads": "b"}`: {"reads must be a list, not a string"}, `{"reads": "b"}`: {"reads must be a list, not a string"},
`{"reads": ["", 3]}`: {"reads item 1 is empty", "reads item 2 must be a string, not a number"}, `{"reads": ["", 3]}`: {"reads item 1 is empty", "reads item 2 must be a string, not a number"},
`{"reads": ["a", "a"]}`: {`reads item 2 repeats "a"`},
} { } {
_, err := New(WithDataFS(fstest.MapFS{".fejkdata.json": {Data: []byte(manifest)}})) _, err := New(WithDataFS(fstest.MapFS{".fejkdata.json": {Data: []byte(manifest)}}))
for _, w := range want { for _, w := range want {