Skip to content

Commit c79435a

Browse files
committed
Use t.TempDir() to access a guaranteed writable directory.
This is available since [Go 1.15](https://tip.golang.org/doc/go1.15#testingpkgtesting).
1 parent 22f439b commit c79435a

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

roaring64/bsi64_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,10 @@ func TestMinMaxWithNilFoundSet(t *testing.T) {
644644
}
645645

646646
func TestBSIWriteToReadFrom(t *testing.T) {
647-
file, err := os.CreateTemp("./testdata", "bsi-test")
647+
file, err := os.CreateTemp(t.TempDir(), "bsi-test")
648648
if err != nil {
649649
t.Fatal(err)
650650
}
651-
defer t.Cleanup(func() { os.Remove(file.Name()) })
652651
defer file.Close()
653652
bsi, min, max := setupRandom()
654653
_, err = bsi.WriteTo(file)

roaring64/serialization_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestSerializationBasic037(t *testing.T) {
8686

8787
func TestSerializationToFile038(t *testing.T) {
8888
rb := BitmapOf(1, 2, 3, 4, 5, 100, 1000)
89-
fname := "myfile.bin"
89+
fname := filepath.Join(t.TempDir(), "myfile.bin")
9090
fout, err := os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o660)
9191
if err != nil {
9292
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
@@ -113,10 +113,7 @@ func TestSerializationToFile038(t *testing.T) {
113113
buf := bytes.NewBuffer(nil)
114114
teer := io.TeeReader(fin, buf)
115115

116-
defer func() {
117-
fin.Close()
118-
_ = os.Remove(fname)
119-
}()
116+
defer fin.Close()
120117

121118
_, _ = newrb.ReadFrom(teer)
122119
assert.True(t, rb.Equals(newrb))

serialization_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestSerializationBasic037(t *testing.T) {
6464

6565
func TestSerializationToFile038(t *testing.T) {
6666
rb := BitmapOf(1, 2, 3, 4, 5, 100, 1000)
67-
fname := "myfile.bin"
67+
fname := filepath.Join(t.TempDir(), "myfile.bin")
6868
fout, err := os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0660)
6969
if err != nil {
7070
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
@@ -89,10 +89,7 @@ func TestSerializationToFile038(t *testing.T) {
8989
return
9090
}
9191

92-
defer func() {
93-
fin.Close()
94-
_ = os.Remove(fname)
95-
}()
92+
defer fin.Close()
9693

9794
_, _ = newrb.ReadFrom(fin)
9895
assert.True(t, rb.Equals(newrb))

0 commit comments

Comments
 (0)