Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rekby committed Sep 24, 2023
1 parent 50b561b commit 32fe5eb
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,35 @@ func Test_Env_CacheResult(t *testing.T) {
at.Equal(second1, second2)
at.NotEqual(first1, second1)
})
t.Run("WithCleanup", func(t *testing.T) {
tMock := &internal.TestMock{TestName: t.Name()}
env := newTestEnv(tMock)

callbackCalled := 0
cleanupCalled := 0
var callbackFunc FixtureFunction = func() (*Result, error) {
callbackCalled++
cleanup := func() {
cleanupCalled++
}
return NewResultWithCleanup(callbackCalled, cleanup), nil
}

res := env.CacheResult(callbackFunc)
require.Equal(t, 1, res)
require.Equal(t, 1, callbackCalled)
require.Equal(t, cleanupCalled, 0)

// got value from cache
res = env.CacheResult(callbackFunc)
require.Equal(t, 1, res)
require.Equal(t, 1, callbackCalled)
require.Equal(t, cleanupCalled, 0)

tMock.CallCleanup()
require.Equal(t, 1, callbackCalled)
require.Equal(t, 1, cleanupCalled)
})
t.Run("Panic", func(t *testing.T) {
at := assert.New(t)
tMock := &internal.TestMock{TestName: "mock", SkipGoexit: true}
Expand Down

0 comments on commit 32fe5eb

Please sign in to comment.