(t *testing.T)
| 43 | } |
| 44 | |
| 45 | func 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 | |
| 73 | func TestCIDFileCloseWithWrite(t *testing.T) { |
| 74 | tempdir := fs.NewDir(t, "test-cid-file") |
nothing calls this directly
no test coverage detected
searching dependent graphs…