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

Function TestJSONSaveWithNoFile

cli/config/config_test.go:333–363  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

331}
332
333func TestJSONSaveWithNoFile(t *testing.T) {
334 js := `{
335 "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv" } },
336 "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}"
337}`
338 config, err := LoadFromReader(strings.NewReader(js))
339 assert.NilError(t, err)
340 err = config.Save()
341 assert.ErrorContains(t, err, "with empty filename")
342
343 tmpHome := t.TempDir()
344
345 fn := filepath.Join(tmpHome, ConfigFileName)
346 f, _ := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
347 defer f.Close()
348
349 assert.NilError(t, config.SaveToWriter(f))
350 buf, err := os.ReadFile(filepath.Join(tmpHome, ConfigFileName))
351 assert.NilError(t, err)
352 expConfStr := `{
353 "auths": {
354 "https://index.docker.io/v1/": {
355 "auth": "am9lam9lOmhlbGxv"
356 }
357 },
358 "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}"
359}`
360 if string(buf) != expConfStr {
361 t.Fatalf("Should have save in new form: \n%s\nnot \n%s", string(buf), expConfStr)
362 }
363}
364
365func TestLoadDefaultConfigFile(t *testing.T) {
366 dir := setupConfigDir(t)

Callers

nothing calls this directly

Calls 4

LoadFromReaderFunction · 0.85
SaveToWriterMethod · 0.80
SaveMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…