diff --git a/env.go b/env.go index a85941f..0f1243a 100644 --- a/env.go +++ b/env.go @@ -141,6 +141,10 @@ func (e *EnvT) CacheResult(f FixtureFunction, options ...CacheOptions) interface var fWithoutCleanup FixtureCallbackFunc = func() (res interface{}, err error) { result, err := f() + if result == nil { + return nil, err + } + resCleanupFunc = result.Cleanup return result.Value, err } diff --git a/env_test.go b/env_test.go index ad28420..5b8b91b 100644 --- a/env_test.go +++ b/env_test.go @@ -380,6 +380,26 @@ func Test_Env_CacheResult(t *testing.T) { rndFix(e, "first") }) }) + t.Run("WithNilResult", func(t *testing.T) { + at := assert.New(t) + tMock := &internal.TestMock{TestName: "mock"} + e := newTestEnv(tMock) + + testErr := errors.New("test err") + + failedFix := func(e Env) int { + return e.CacheResult(func() (*Result, error) { + return nil, testErr + }).(int) + } + done := make(chan bool) + go func() { + defer close(done) + failedFix(e) + }() + <-done + at.Equal(1, len(tMock.Fatals)) + }) } func Test_FixtureWrapper(t *testing.T) {