Skip to content

Commit

Permalink
commitlog: better temp dir use
Browse files Browse the repository at this point in the history
  • Loading branch information
travisjeffery committed Aug 6, 2018
1 parent d893db1 commit 87f6136
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions commitlog/commitlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package commitlog_test

import (
"bytes"
"fmt"
"math/rand"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -147,8 +145,10 @@ func setup(t require.TestingT) *commitlog.CommitLog {
}

func setupWithOptions(t require.TestingT, opts commitlog.Options) *commitlog.CommitLog {
var err error
if opts.Path == "" {
opts.Path = filepath.Join(os.TempDir(), fmt.Sprintf("commitlogtest%d", rand.Int63()))
opts.Path, err = ioutil.TempDir("", "commitlogtest")
require.NoError(t, err)
}
l, err := commitlog.New(opts)
require.NoError(t, err)
Expand Down
4 changes: 3 additions & 1 deletion commitlog/compact_cleaner_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commitlog_test

import (
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -43,7 +44,8 @@ func TestCompactCleaner(t *testing.T) {
Timestamp: time.Now(),
}))

path := os.TempDir()
path, err := ioutil.TempDir("", "commitlog-delete-cleaner")
req.NoError(err)
defer os.RemoveAll(path)

l := setupWithOptions(t, commitlog.Options{
Expand Down
6 changes: 3 additions & 3 deletions commitlog/delete_cleaner_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commitlog_test

import (
"fmt"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -44,8 +44,8 @@ func TestDeleteCleaner(t *testing.T) {
Timestamp: time.Now(),
}))

path := os.TempDir()
fmt.Println(path)
path, err := ioutil.TempDir("", "commitlog-delete-cleaner")
req.NoError(err)
defer os.RemoveAll(path)

l := setupWithOptions(t, commitlog.Options{
Expand Down
11 changes: 7 additions & 4 deletions commitlog/index_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package commitlog

import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestIndex(t *testing.T) {
path := filepath.Join(os.TempDir(), fmt.Sprintf(fileFormat, rand.Int63(), indexSuffix))
path, err := ioutil.TempDir("", "commitlog-index")
require.NoError(t, err)

totalEntries := rand.Intn(10) + 10
//case for roundDown
bytes := int64(totalEntries*entryWidth + 1)
Expand Down Expand Up @@ -72,7 +73,9 @@ func TestIndex(t *testing.T) {
}

func TestIndexScanner(t *testing.T) {
path := filepath.Join(os.TempDir(), fmt.Sprintf(fileFormat, rand.Int63(), indexSuffix))
path, err := ioutil.TempDir("", "commitlog-index")
require.NoError(t, err)

totalEntries := rand.Intn(10) + 10
//case for roundDown
bytes := int64(totalEntries*entryWidth + 1)
Expand Down

0 comments on commit 87f6136

Please sign in to comment.