github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/experimental/close_test.go (about) 1 package experimental_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/bananabytelabs/wazero/experimental" 8 "github.com/bananabytelabs/wazero/internal/close" 9 "github.com/bananabytelabs/wazero/internal/testing/require" 10 ) 11 12 // testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors. 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 }