Debian Codegraph @

experimental/sock/sock_test.go

raw
1 package sock_test
2
3 import (
4 "context"
5 "testing"
6
7 "github.com/tetratelabs/wazero/experimental/sock"
8 internalsock "github.com/tetratelabs/wazero/internal/sock"
9 "github.com/tetratelabs/wazero/internal/testing/require"
10 )
11
12 type arbitrary struct{}
13
14 // testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
15 var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")
16
17 func TestWithSockConfig(t *testing.T) {
18 tests := []struct {
19 name string
20 sockCfg sock.Config
21 expected bool
22 }{
23 {
24 name: "returns input when sockCfg nil",
25 expected: false,
26 },
27 {
28 name: "returns input when sockCfg empty",
29 sockCfg: sock.NewConfig(),
30 expected: false,
31 },
32 {
33 name: "decorates with sockCfg",
34 sockCfg: sock.NewConfig().WithTCPListener("", 0),
35 expected: true,
36 },
37 }
38
39 for _, tt := range tests {
40 tc := tt
41 t.Run(tc.name, func(t *testing.T) {
42 if decorated := sock.WithConfig(testCtx, tc.sockCfg); tc.expected {
43 require.NotNil(t, decorated.Value(internalsock.ConfigKey{}))
44 } else {
45 require.Same(t, testCtx, decorated)
46 }
47 })
48 }
49 }