You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
boundary/internal/daemon/worker/proxy/options_test.go

49 lines
1.3 KiB

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package proxy
import (
"net"
"reflect"
"runtime"
"testing"
serverpb "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
"github.com/stretchr/testify/assert"
)
func Test_GetOpts(t *testing.T) {
t.Parallel()
t.Run("WithInjectedApplicationCredentials", func(t *testing.T) {
assert := assert.New(t)
c := &serverpb.Credential{
Credential: &serverpb.Credential_UsernamePassword{
UsernamePassword: &serverpb.UsernamePassword{
Username: "user",
Password: "pass",
},
},
}
opts := GetOpts(WithInjectedApplicationCredentials([]*serverpb.Credential{c}))
testOpts := getDefaultOptions()
assert.NotEqual(opts, testOpts)
testOpts.WithInjectedApplicationCredentials = []*serverpb.Credential{c}
assert.Equal(opts, testOpts)
})
t.Run("WithPostConnectionHook", func(t *testing.T) {
assert := assert.New(t)
testFn := func(net.Conn) {}
opts := GetOpts(WithPostConnectionHook(testFn))
testOpts := getDefaultOptions()
assert.NotEqual(opts, testOpts)
testOpts.WithPostConnectionHook = testFn
assert.Equal(
runtime.FuncForPC(reflect.ValueOf(opts.WithPostConnectionHook).Pointer()).Name(),
runtime.FuncForPC(reflect.ValueOf(testOpts.WithPostConnectionHook).Pointer()).Name(),
)
})
}