MCPcopy Create free account
hub / github.com/docker/cli / TestSaveWithSymlink

Function TestSaveWithSymlink

cli/config/configfile/file_test.go:641–666  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

639}
640
641func TestSaveWithSymlink(t *testing.T) {
642 dir := fs.NewDir(t, t.Name(), fs.WithFile("real-config.json", `{}`))
643 defer dir.Remove()
644
645 symLink := dir.Join("config.json")
646 realFile := dir.Join("real-config.json")
647 err := os.Symlink(realFile, symLink)
648 assert.NilError(t, err)
649
650 configFile := New(symLink)
651
652 err = configFile.Save()
653 assert.NilError(t, err)
654
655 fi, err := os.Lstat(symLink)
656 assert.NilError(t, err)
657 assert.Assert(t, fi.Mode()&os.ModeSymlink != 0, "expected %s to be a symlink", symLink)
658
659 cfg, err := os.ReadFile(symLink)
660 assert.NilError(t, err)
661 assert.Check(t, is.Equal(string(cfg), "{\n \"auths\": {}\n}"))
662
663 cfg, err = os.ReadFile(realFile)
664 assert.NilError(t, err)
665 assert.Check(t, is.Equal(string(cfg), "{\n \"auths\": {}\n}"))
666}
667
668func TestSaveWithRelativeSymlink(t *testing.T) {
669 dir := fs.NewDir(t, t.Name(), fs.WithFile("real-config.json", `{}`))

Callers

nothing calls this directly

Calls 5

ModeMethod · 0.80
NewFunction · 0.70
RemoveMethod · 0.65
SaveMethod · 0.65
NameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…