-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient_test.go
83 lines (72 loc) · 1.76 KB
/
client_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
package vaultsecrets
import (
"os"
"reflect"
"testing"
)
var client = Client{
OrganizationID: os.Getenv("HCP_ORGANIZATION_ID"),
ProjectID: os.Getenv("HCP_PROJECT_ID"),
ApplicationName: os.Getenv("HCP_APPLICATION_NAME"),
ClientID: os.Getenv("HCP_CLIENT_ID"),
ClientSecret: os.Getenv("HCP_CLIENT_SECRET"),
}
func TestAuthenticate(t *testing.T) {
if err := client.Authenticate(); err != nil {
t.Errorf("client Authenticate error: %s", err)
}
if client.AccessToken == "" {
t.Errorf("client Authenticate error: Could not retrieve access token.")
}
}
func TestGet(t *testing.T) {
tests := []struct {
secretName string
expectedValue string
}{
{"NOT_FOUND_SECRET", ""},
{"SDK_TEST", "OK"},
}
for _, test := range tests {
secret, _ := client.Get(test.secretName)
if secret != test.expectedValue {
t.Errorf("client Get error: Could not meet expected value.")
}
}
}
func TestList(t *testing.T) {
secrets, err := client.List()
if err != nil {
t.Errorf("client List error: %s", err)
}
if !reflect.DeepEqual(secrets, []string{"MY_APP_SECRET", "SDK_TEST"}) {
t.Errorf("client List error: Could not meet expected value.")
}
}
func TestGetAll(t *testing.T) {
secrets, err := client.GetAll()
if err != nil {
t.Errorf("client GetAll error: %s", err)
}
if !reflect.DeepEqual(
secrets,
map[string]string{
"MY_APP_SECRET": "TEST",
"SDK_TEST": "OK",
},
) {
t.Errorf("client GetAll error: Could not meet expected value.")
}
}
func TestNewClient(t *testing.T) {
_, err := NewClient(
os.Getenv("HCP_ORGANIZATION_ID"),
os.Getenv("HCP_PROJECT_ID"),
os.Getenv("HCP_APPLICATION_NAME"),
os.Getenv("HCP_CLIENT_ID"),
os.Getenv("HCP_CLIENT_SECRET"),
)
if err != nil {
t.Errorf("client NewClient error: %s", err)
}
}