Some checks failed
Release CLI / Pre-release build (push) Has been cancelled
Release CLI / Pre-release test (macos-12) (push) Has been cancelled
Release CLI / Pre-release test (ubuntu-22.04) (push) Has been cancelled
Release CLI / Pre-release test (windows-2022) (push) Has been cancelled
Release CLI / Release (push) Has been cancelled
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com> Signed-off-by: Adrian Cole <adrian@tetrate.io> Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com> Co-authored-by: Achille <achille.roussel@gmail.com> Co-authored-by: Adrian Cole <adrian@tetrate.io>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package sock_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/tetratelabs/wazero/experimental/sock"
|
|
internalsock "github.com/tetratelabs/wazero/internal/sock"
|
|
"github.com/tetratelabs/wazero/internal/testing/require"
|
|
)
|
|
|
|
// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
|
|
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
|
|
|
|
func TestWithSockConfig(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
sockCfg sock.Config
|
|
expected bool
|
|
}{
|
|
{
|
|
name: "returns input when sockCfg nil",
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "returns input when sockCfg empty",
|
|
sockCfg: sock.NewConfig(),
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "decorates with sockCfg",
|
|
sockCfg: sock.NewConfig().WithTCPListener("", 0),
|
|
expected: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tc := tt
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if decorated := sock.WithConfig(testCtx, tc.sockCfg); tc.expected {
|
|
require.NotNil(t, decorated.Value(internalsock.ConfigKey{}))
|
|
} else {
|
|
require.Same(t, testCtx, decorated)
|
|
}
|
|
})
|
|
}
|
|
}
|