MCPcopy Create free account
hub / github.com/crawshaw/jsonfile / TestBadLoad

Function TestBadLoad

jsonfile_test.go:155–172  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

153}
154
155func TestBadLoad(t *testing.T) {
156 t.Parallel()
157 type DB struct{ Val int }
158
159 path := filepath.Join(t.TempDir(), "testbadload.json")
160 _, err := Load[DB](path)
161 if !errors.Is(err, os.ErrNotExist) {
162 t.Fatalf("Load err=%v, want %v", err, os.ErrNotExist)
163 }
164
165 if err := os.WriteFile(path, []byte("not json"), 0666); err != nil {
166 t.Fatal(err)
167 }
168 _, err = Load[DB](path)
169 if err == nil || !strings.Contains(err.Error(), "invalid character") {
170 t.Fatalf("Load err=%v, want error", err)
171 }
172}
173
174func TestBadNew(t *testing.T) {
175 t.Parallel()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…