diff --git a/lib/ttlmap/ttlmap_test.go b/lib/ttlmap/ttlmap_test.go index d632b500..4a5210f2 100644 --- a/lib/ttlmap/ttlmap_test.go +++ b/lib/ttlmap/ttlmap_test.go @@ -3,6 +3,7 @@ package ttlmap import ( "fmt" "os" + "path/filepath" "time" "github.com/stretchr/testify/assert" @@ -10,9 +11,7 @@ import ( ) func (t *TTLMapTestSuite) TestTTLMap_Complete() { - fp := "/tmp/test.yaml" - assert.NoError(t.T(), os.RemoveAll(fp)) - defer os.RemoveAll(fp) + fp := filepath.Join(t.T().TempDir(), "test.yaml") store := NewMap(fp, 100*time.Millisecond, 120*time.Millisecond) keyToDuration := map[string]time.Duration{ @@ -68,13 +67,13 @@ func (t *TTLMapTestSuite) TestTTLMap_Complete() { _, isOk = store.Get("xyz") assert.True(t.T(), isOk, "xyz") + + store.closeChan <- struct{}{} } func (t *TTLMapTestSuite) TestFlushing() { // Step 1: Create a TTLMap instance with a temporary file for storage - fp := "/tmp/test2.yaml" - assert.NoError(t.T(), os.RemoveAll(fp)) - defer os.RemoveAll(fp) + fp := filepath.Join(t.T().TempDir(), "test.yaml") ttlMap := NewMap(fp, DefaultCleanUpInterval, DefaultFlushInterval) @@ -95,4 +94,6 @@ func (t *TTLMapTestSuite) TestFlushing() { assert.NoError(t.T(), err) assert.Equal(t.T(), 1, len(data)) + + ttlMap.closeChan <- struct{}{} } diff --git a/sources/dynamodb/offsets/offsets_test.go b/sources/dynamodb/offsets/offsets_test.go index 30ef0897..7a1bc3cc 100644 --- a/sources/dynamodb/offsets/offsets_test.go +++ b/sources/dynamodb/offsets/offsets_test.go @@ -2,7 +2,7 @@ package offsets import ( "fmt" - "os" + "path/filepath" "time" "github.com/stretchr/testify/assert" @@ -13,10 +13,7 @@ func ptrDuration(d time.Duration) *time.Duration { } func (o *OffsetsTestSuite) TestOffsets_Complete() { - offsetsFilePath := "/tmp/offsets-test" - assert.NoError(o.T(), os.RemoveAll(offsetsFilePath)) // Delete if prev run wasn't clean. - - defer assert.NoError(o.T(), os.RemoveAll(offsetsFilePath)) // Delete the file we do create during the test. + offsetsFilePath := filepath.Join(o.T().TempDir(), "offsets-test") storage := NewStorage(offsetsFilePath, ptrDuration(50*time.Millisecond), ptrDuration(50*time.Millisecond)) processedShards := []string{"foo", "bar", "xyz"}