diff --git a/dkron/store_test.go b/dkron/store_test.go index d30780385..aecee16ee 100644 --- a/dkron/store_test.go +++ b/dkron/store_test.go @@ -1,18 +1,23 @@ package dkron import ( + "io/ioutil" + "os" "testing" "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestStore(t *testing.T) { - s, err := NewStore(nil, "test1.data") + dir, err := ioutil.TempDir("", "dkron-test") + require.NoError(t, err) + defer os.RemoveAll(dir) + + s, err := NewStore(nil, dir) + require.NoError(t, err) defer s.Shutdown() - if err != nil { - t.Fatal(err) - } testJob := &Job{ Name: "test", @@ -77,12 +82,6 @@ func TestStore(t *testing.T) { } func TestStore_GetLastExecutionGroup(t *testing.T) { - s, err := NewStore(nil, "test2.data") - defer s.Shutdown() - if err != nil { - t.Fatal(err) - } - // This can not use time.Now() because that will include monotonic information // that will cause the unmarshalled execution to differ from our generated version // See `go doc time` @@ -192,6 +191,11 @@ func TestStore_GetLastExecutionGroup(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + dir, err := ioutil.TempDir("", "dkron-test") + require.NoError(t, err) + s, err := NewStore(nil, dir) + require.NoError(t, err) + for _, e := range tt.addExecutions { s.SetExecution(e) } @@ -204,6 +208,11 @@ func TestStore_GetLastExecutionGroup(t *testing.T) { for _, w := range tt.want { assert.Contains(t, got, w) } + + err = s.Shutdown() + require.NoError(t, err) + err = os.RemoveAll(dir) + require.NoError(t, err) }) } }