forked from hashicorp/vault-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_option_test.go
69 lines (60 loc) · 1.56 KB
/
client_option_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package vault
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func Test_New(t *testing.T) {
cases := map[string]struct {
options []ClientOption
}{
"empty": {
options: nil,
},
"with-base-address": {
options: []ClientOption{WithAddress("http://test")},
},
"with-base-address-with-request-timeout": {
options: []ClientOption{WithAddress("http://test"), WithRequestTimeout(30 * time.Second)},
},
"with-enforce-read-your-writes-consistency": {
options: []ClientOption{WithEnforceReadYourWritesConsistency()},
},
"with-retry-configuration": {
options: []ClientOption{WithRetryConfiguration(
RetryConfiguration{
RetryWaitMin: 200 * time.Millisecond,
RetryWaitMax: 900 * time.Millisecond,
},
)},
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
client, err := New(tc.options...)
require.NoError(t, err)
// unset the base client pointers since they are always different
configurationDefault := DefaultConfiguration()
configurationDefault.HTTPClient = nil
configurationClient := client.Configuration()
configurationClient.HTTPClient = nil
// check if the configurations were modified
if len(tc.options) == 0 {
require.Equal(
t,
fmt.Sprintf("%v", configurationDefault),
fmt.Sprintf("%v", configurationClient),
)
} else {
require.NotEqual(
t,
fmt.Sprintf("%v", configurationDefault),
fmt.Sprintf("%v", configurationClient),
)
}
})
}
}