2023-02-02 17:15:17 -08:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2020-07-24 10:23:35 -04:00
|
|
|
package password
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-07-29 07:58:19 -04:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-07-24 10:23:35 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Test_GetOpts(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
2020-08-07 10:18:40 -07:00
|
|
|
t.Run("WithPublicId", func(t *testing.T) {
|
2022-10-25 21:33:31 -04:00
|
|
|
opts := GetOpts(WithPublicId("test id"))
|
2020-08-07 10:18:40 -07:00
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withPublicId = "test id"
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2020-08-12 08:20:35 -07:00
|
|
|
t.Run("WithLoginName", func(t *testing.T) {
|
2022-10-25 21:33:31 -04:00
|
|
|
opts := GetOpts(WithLoginName("test"))
|
2020-08-12 08:20:35 -07:00
|
|
|
testOpts := getDefaultOptions()
|
2022-10-25 21:33:31 -04:00
|
|
|
testOpts.WithLoginName = "test"
|
2020-08-12 08:20:35 -07:00
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2020-07-24 10:23:35 -04:00
|
|
|
t.Run("WithName", func(t *testing.T) {
|
2022-10-25 21:33:31 -04:00
|
|
|
opts := GetOpts(WithName("test"))
|
2020-07-24 10:23:35 -04:00
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withName = "test"
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
|
|
|
|
t.Run("WithDescription", func(t *testing.T) {
|
2022-10-25 21:33:31 -04:00
|
|
|
opts := GetOpts(WithDescription("test desc"))
|
2020-07-24 10:23:35 -04:00
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withDescription = "test desc"
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2020-07-24 11:38:27 -07:00
|
|
|
t.Run("WithLimit", func(t *testing.T) {
|
2022-10-25 21:33:31 -04:00
|
|
|
opts := GetOpts(WithLimit(5))
|
2020-07-24 11:38:27 -07:00
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withLimit = 5
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2020-07-31 11:18:41 -04:00
|
|
|
t.Run("WithPassword", func(t *testing.T) {
|
2022-10-25 21:33:31 -04:00
|
|
|
opts := GetOpts(WithPassword("test password"))
|
2020-07-31 11:18:41 -04:00
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.password = "test password"
|
|
|
|
|
testOpts.withPassword = true
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2020-07-29 07:58:19 -04:00
|
|
|
t.Run("WithConfiguration", func(t *testing.T) {
|
|
|
|
|
conf := NewArgon2Configuration()
|
|
|
|
|
conf.KeyLength = conf.KeyLength * 2
|
2022-10-25 21:33:31 -04:00
|
|
|
opts := GetOpts(WithConfiguration(conf))
|
2020-07-29 07:58:19 -04:00
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
c, ok := testOpts.withConfig.(*Argon2Configuration)
|
|
|
|
|
require.True(t, ok, "need an Argon2Configuration")
|
|
|
|
|
c.KeyLength = c.KeyLength * 2
|
|
|
|
|
testOpts.withConfig = c
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2021-04-08 20:54:32 -04:00
|
|
|
t.Run("WithOrderByCreateTime", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
2022-10-25 21:33:31 -04:00
|
|
|
opts := GetOpts(WithOrderByCreateTime(true))
|
2021-04-08 20:54:32 -04:00
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withOrderByCreateTime = true
|
|
|
|
|
testOpts.ascending = true
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
2020-07-24 10:23:35 -04:00
|
|
|
}
|