...
1 package experimental_test
2
3 import (
4 "context"
5 "testing"
6
7 "github.com/tetratelabs/wazero/experimental"
8 "github.com/tetratelabs/wazero/internal/close"
9 "github.com/tetratelabs/wazero/internal/testing/require"
10 )
11
12
13 var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
14
15 func TestWithCloseNotifier(t *testing.T) {
16 tests := []struct {
17 name string
18 notification experimental.CloseNotifier
19 expected bool
20 }{
21 {
22 name: "returns input when notification nil",
23 expected: false,
24 },
25 {
26 name: "decorates with notification",
27 notification: experimental.CloseNotifyFunc(func(context.Context, uint32) {}),
28 expected: true,
29 },
30 }
31
32 for _, tt := range tests {
33 tc := tt
34 t.Run(tc.name, func(t *testing.T) {
35 if decorated := experimental.WithCloseNotifier(testCtx, tc.notification); tc.expected {
36 require.NotNil(t, decorated.Value(close.NotifierKey{}))
37 } else {
38 require.Same(t, testCtx, decorated)
39 }
40 })
41 }
42 }
43
View as plain text