MCPcopy Index your code
hub / github.com/docker/cli / TestCorruptMetadata

Function TestCorruptMetadata

cli/context/store/store_test.go:239–262  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

237}
238
239func TestCorruptMetadata(t *testing.T) {
240 tempDir := t.TempDir()
241 s := New(tempDir, testCfg)
242 err := s.CreateOrUpdate(
243 Metadata{
244 Endpoints: map[string]any{
245 "ep1": endpoint{Foo: "bar"},
246 },
247 Metadata: context{Bar: "baz"},
248 Name: "source",
249 })
250 assert.NilError(t, err)
251
252 // Simulate the meta.json file getting corrupted
253 // by some external process.
254 contextDir := s.meta.contextDir(contextdirOf("source"))
255 contextFile := filepath.Join(contextDir, metaFile)
256 err = os.WriteFile(contextFile, nil, 0o600)
257 assert.NilError(t, err)
258
259 // Assert that the error message gives the user some clue where to look.
260 _, err = s.GetMetadata("source")
261 assert.ErrorContains(t, err, fmt.Sprintf("parsing %s: unexpected end of JSON input", contextFile))
262}
263
264func TestNames(t *testing.T) {
265 names, err := Names(nil)

Callers

nothing calls this directly

Calls 5

contextdirOfFunction · 0.85
NewFunction · 0.70
CreateOrUpdateMethod · 0.65
GetMetadataMethod · 0.65
contextDirMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…