-
Notifications
You must be signed in to change notification settings - Fork 10
/
config_test.go
155 lines (143 loc) · 2.43 KB
/
config_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package gcpkms
import (
"reflect"
"testing"
"github.com/hashicorp/vault/sdk/framework"
)
func TestConfig_Update(t *testing.T) {
cases := []struct {
name string
new *Config
d *framework.FieldData
r *Config
changed bool
err bool
}{
{
"empty",
&Config{},
nil,
&Config{},
false,
false,
},
{
"keeps_existing",
&Config{
Credentials: "creds",
},
nil,
&Config{
Credentials: "creds",
},
false,
false,
},
{
"overwrites_changes",
&Config{
Credentials: "creds",
},
&framework.FieldData{
Raw: map[string]interface{}{
"credentials": "foo",
},
},
&Config{
Credentials: "foo",
},
true,
false,
},
{
"overwrites_and_new",
&Config{
Credentials: "creds",
},
&framework.FieldData{
Raw: map[string]interface{}{
"credentials": "foo",
"scopes": "bar",
},
},
&Config{
Credentials: "foo",
Scopes: []string{"bar"},
},
true,
false,
},
{
"no_changes_order",
&Config{
Scopes: []string{"bar", "foo"},
},
&framework.FieldData{
Raw: map[string]interface{}{
"scopes": "foo,bar",
},
},
&Config{
Scopes: []string{"bar", "foo"},
},
false,
false,
},
{
"no_changes_caps",
&Config{
Scopes: []string{"bar", "foo"},
},
&framework.FieldData{
Raw: map[string]interface{}{
"scopes": "FOO,baR",
},
},
&Config{
Scopes: []string{"bar", "foo"},
},
false,
false,
},
{
"no_changes_dupes",
&Config{
Scopes: []string{"bar", "foo"},
},
&framework.FieldData{
Raw: map[string]interface{}{
"scopes": "foo, foo, foo, bar",
},
},
&Config{
Scopes: []string{"bar", "foo"},
},
false,
false,
},
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
if tc.d != nil {
var b backend
tc.d.Schema = b.pathConfig().Fields
}
changed, err := tc.new.Update(tc.d)
if (err != nil) != tc.err {
t.Fatal(err)
}
if changed != tc.changed {
t.Errorf("expected %t to be %t", changed, tc.changed)
}
if v, exp := tc.new.Scopes, tc.r.Scopes; !reflect.DeepEqual(v, exp) {
t.Errorf("expected %q to be %q", v, exp)
}
if v, exp := tc.new.Credentials, tc.r.Credentials; v != exp {
t.Errorf("expected %q to be %q", v, exp)
}
})
}
}