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

Function TestCIDFileCloseWithNoWrite

cli/command/container/create_test.go:45–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestCIDFileCloseWithNoWrite(t *testing.T) {
46 // Closing should remove the file if it was not written to.
47 t.Run("closing should remove file", func(t *testing.T) {
48 filename := filepath.Join(t.TempDir(), "cidfile-1")
49 file, err := newCIDFile(filename)
50 assert.NilError(t, err)
51 assert.Check(t, is.Equal(file.path, filename))
52
53 assert.NilError(t, file.Close())
54 _, err = os.Stat(filename)
55 assert.Check(t, os.IsNotExist(err))
56 })
57
58 // Closing (and removing) the file should not produce an error if the file no longer exists.
59 t.Run("close should remove file", func(t *testing.T) {
60 filename := filepath.Join(t.TempDir(), "cidfile-2")
61 file, err := newCIDFile(filename)
62 assert.NilError(t, err)
63 assert.Check(t, is.Equal(file.path, filename))
64
65 assert.NilError(t, os.Remove(filename))
66 _, err = os.Stat(filename)
67 assert.Check(t, os.IsNotExist(err))
68
69 assert.NilError(t, file.Close())
70 })
71}
72
73func TestCIDFileCloseWithWrite(t *testing.T) {
74 tempdir := fs.NewDir(t, "test-cid-file")

Callers

nothing calls this directly

Calls 3

newCIDFileFunction · 0.85
RemoveMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…