2021-05-04 19:57:35 -05:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-02-02 17:15:17 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2021-04-08 20:54:32 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2021-05-04 19:57:35 -05:00
|
|
|
"github.com/hashicorp/boundary/internal/perms"
|
2021-04-08 20:54:32 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-05-04 19:57:35 -05:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-04-08 20:54:32 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Test_GetOpts provides unit tests for GetOpts and all the options
|
|
|
|
|
func Test_GetOpts(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
t.Run("WithDiscardUnknownFields", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
2021-04-13 18:07:50 -05:00
|
|
|
|
|
|
|
|
opts := GetOpts()
|
2021-04-08 20:54:32 -04:00
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
|
2021-04-13 18:07:50 -05:00
|
|
|
opts = GetOpts(WithDiscardUnknownFields(true))
|
2021-04-08 20:54:32 -04:00
|
|
|
testOpts = getDefaultOptions()
|
|
|
|
|
testOpts.withDiscardUnknownFields = true
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
|
2021-04-13 18:07:50 -05:00
|
|
|
opts = GetOpts(WithDiscardUnknownFields(false))
|
2021-04-08 20:54:32 -04:00
|
|
|
testOpts = getDefaultOptions()
|
|
|
|
|
testOpts.withDiscardUnknownFields = false
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
2021-05-04 19:57:35 -05:00
|
|
|
t.Run("WithUserIsAnonymous", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
|
|
opts := GetOpts()
|
|
|
|
|
assert.False(opts.WithUserIsAnonymous)
|
2021-04-14 15:49:08 -05:00
|
|
|
|
2021-05-04 19:57:35 -05:00
|
|
|
opts = GetOpts(WithUserIsAnonymous(true))
|
|
|
|
|
assert.True(opts.WithUserIsAnonymous)
|
|
|
|
|
})
|
|
|
|
|
t.Run("WithOutputFields", func(t *testing.T) {
|
2021-04-14 15:49:08 -05:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
|
|
opts := GetOpts()
|
2021-05-04 19:57:35 -05:00
|
|
|
assert.Nil(opts.WithOutputFields)
|
|
|
|
|
|
2023-01-06 17:27:19 -06:00
|
|
|
var out perms.OutputFields
|
2021-04-14 15:49:08 -05:00
|
|
|
|
2021-05-04 19:57:35 -05:00
|
|
|
opts = GetOpts(WithOutputFields(&out))
|
2023-01-06 17:27:19 -06:00
|
|
|
assert.NotNil(opts.WithOutputFields)
|
2021-04-14 15:49:08 -05:00
|
|
|
})
|
2021-06-02 13:01:37 -05:00
|
|
|
t.Run("WithManagedGroupIds", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
|
|
opts := GetOpts()
|
|
|
|
|
assert.Nil(opts.WithManagedGroupIds)
|
|
|
|
|
|
|
|
|
|
out := []string{"foobar"}
|
|
|
|
|
|
|
|
|
|
opts = GetOpts(WithManagedGroupIds(out))
|
|
|
|
|
require.Equal(out, opts.WithManagedGroupIds)
|
|
|
|
|
})
|
2021-06-02 13:05:10 -05:00
|
|
|
t.Run("WithMemberIds", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
|
|
opts := GetOpts()
|
|
|
|
|
assert.Nil(opts.WithMemberIds)
|
|
|
|
|
|
|
|
|
|
out := []string{"foobar"}
|
|
|
|
|
|
|
|
|
|
opts = GetOpts(WithMemberIds(out))
|
|
|
|
|
require.Equal(out, opts.WithMemberIds)
|
|
|
|
|
})
|
2021-11-13 17:18:20 -05:00
|
|
|
t.Run("WithHostSetIds", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
|
|
opts := GetOpts()
|
|
|
|
|
assert.Nil(opts.WithHostSetIds)
|
|
|
|
|
|
|
|
|
|
out := []string{"foobar"}
|
|
|
|
|
|
|
|
|
|
opts = GetOpts(WithHostSetIds(out))
|
|
|
|
|
require.Equal(out, opts.WithHostSetIds)
|
|
|
|
|
})
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|