Skip to content

Commit

Permalink
Use TempDir() instead of /tmp for tests (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie authored Jan 24, 2024
1 parent 784a561 commit e1caa9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 7 additions & 6 deletions lib/ttlmap/ttlmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package ttlmap
import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
)

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{
Expand Down Expand Up @@ -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)

Expand All @@ -95,4 +94,6 @@ func (t *TTLMapTestSuite) TestFlushing() {
assert.NoError(t.T(), err)

assert.Equal(t.T(), 1, len(data))

ttlMap.closeChan <- struct{}{}
}
7 changes: 2 additions & 5 deletions sources/dynamodb/offsets/offsets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package offsets

import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/stretchr/testify/assert"
Expand All @@ -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"}
Expand Down

0 comments on commit e1caa9a

Please sign in to comment.