forked from hashicorp/vault-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_option_test.go
62 lines (56 loc) · 1.61 KB
/
request_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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package vault
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_requestOptionsToRequestModifiers(t *testing.T) {
cases := map[string]struct {
options []RequestOption
expected requestModifiers
expectedError bool
}{
"nil": {
options: nil,
expected: requestModifiers{},
expectedError: false,
},
"empty": {
options: []RequestOption{},
expected: requestModifiers{},
expectedError: false,
},
"with-token": {
options: []RequestOption{WithToken("a-token")},
expected: requestModifiers{headers: requestHeaders{token: "a-token"}},
expectedError: false,
},
"with-bad-token": {
options: []RequestOption{WithToken("\u200b")},
expected: requestModifiers{headers: requestHeaders{token: "a-token"}},
expectedError: true,
},
"with-namespace": {
options: []RequestOption{WithNamespace("a-namespace")},
expected: requestModifiers{headers: requestHeaders{namespace: "a-namespace"}},
expectedError: false,
},
"with-token-namespace": {
options: []RequestOption{WithToken("a-token"), WithNamespace("a-namespace")},
expected: requestModifiers{headers: requestHeaders{token: "a-token", namespace: "a-namespace"}},
expectedError: false,
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
actual, err := requestOptionsToRequestModifiers(tc.options)
if tc.expectedError {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, tc.expected, actual)
}
})
}
}