-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpath_config_test.go
113 lines (100 loc) · 2.5 KB
/
path_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
package artifactory
import (
"context"
"testing"
"github.com/hashicorp/vault/sdk/logical"
)
func TestConfig_Write(t *testing.T) {
tests := []struct {
expectation Expectation
data map[string]interface{}
}{
{
ExpectedToSucceed,
map[string]interface{}{
"address": "https://example.com/artifactory",
"api_key": "abc123",
},
},
{
ExpectedToSucceed,
map[string]interface{}{
"address": "https://example.com/artifactory",
"username": "admin",
"password": "password",
},
},
{
ExpectedToSucceed,
map[string]interface{}{
"address": "https://example.com/artifactory",
"api_key": "abc123",
"tls_verify": false,
},
},
{
FailWithLogicalError,
map[string]interface{}{
"address": "https://example.com/artifactory",
"username": "admin",
},
},
{
FailWithLogicalError,
map[string]interface{}{
"address": "https://example.com/artifactory",
"api_key": "abc123",
"username": "admin",
},
},
{
FailWithLogicalError,
map[string]interface{}{
"address": "https://example.com/artifactory",
"api_key": "abc123",
"username": "admin",
"password": "password",
},
},
{FailWithLogicalError, map[string]interface{}{"address": "https://example.com/artifactory"}},
{FailWithLogicalError, map[string]interface{}{"api_key": "abc123"}},
{FailWithLogicalError, map[string]interface{}{}},
}
for _, test := range tests {
b, storage := newBackend(t)
req := &logical.Request{
Operation: logical.UpdateOperation,
Path: "config",
Storage: storage,
Data: test.data,
}
resp, err := b.HandleRequest(context.Background(), req)
assertLogicalResponse(t, test.expectation, err, resp)
}
}
func TestConfig_WriteIdempotent(t *testing.T) {
b, storage := newBackend(t)
data := map[string]interface{}{
"address": "https://example.com/artifactory",
"api_key": "abc123",
}
req := &logical.Request{
Operation: logical.UpdateOperation,
Path: "config",
Storage: storage,
Data: data,
}
resp, err := b.HandleRequest(context.Background(), req)
assertLogicalResponse(t, ExpectedToSucceed, err, resp)
req = &logical.Request{
Operation: logical.ReadOperation,
Path: "config",
Storage: storage,
Data: nil,
}
resp, err = b.HandleRequest(context.Background(), req)
assertLogicalResponse(t, ExpectedToSucceed, err, resp)
if resp.Data["address"] != data["address"] {
t.Fatalf("Read address did not equal expected: %v", resp.Data["address"])
}
}