Skip to content

Commit 150ed59

Browse files
committed
add context fixture
1 parent e32aba2 commit 150ed59

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

sf/context.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package sf
2+
3+
import (
4+
"context"
5+
"github.com/rekby/fixenv"
6+
)
7+
8+
func Context(e fixenv.Env) context.Context {
9+
return fixenv.CacheWithCleanup(e, nil, nil, func() (context.Context, fixenv.FixtureCleanupFunc, error) {
10+
ctx, ctxCancel := context.WithCancel(context.Background())
11+
return ctx, fixenv.FixtureCleanupFunc(ctxCancel), nil
12+
})
13+
}

sf/context_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package sf
2+
3+
import (
4+
"context"
5+
"github.com/rekby/fixenv"
6+
"github.com/rekby/fixenv/internal"
7+
"testing"
8+
)
9+
10+
func TestContext(t *testing.T) {
11+
tm := &internal.TestMock{}
12+
13+
e := fixenv.New(tm)
14+
ctx := Context(e)
15+
if ctx.Err() != nil {
16+
t.Fatal(ctx.Err())
17+
}
18+
19+
tm.CallCleanup()
20+
if ctx.Err() != context.Canceled {
21+
t.Fatal(ctx.Err())
22+
}
23+
}

0 commit comments

Comments
 (0)