-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathkv_v1_test.go
104 lines (75 loc) · 2.96 KB
/
kv_v1_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
package vault_test
import (
"context"
"testing"
"github.com/stretchr/testify/require"
vault "github.com/mittwald/vaultgo"
"github.com/mittwald/vaultgo/test/testdata"
"github.com/stretchr/testify/suite"
)
type KVv1TestSuite struct {
suite.Suite
client *vault.KVv1
}
func TestKVv1TestSuite(t *testing.T) {
for _, v := range testdata.VaultVersions {
require.NoError(t, testdata.Init(context.Background(), v))
t.Logf("using vault uri %v", testdata.Vault.URI())
client, _ := vault.NewClient(testdata.Vault.URI(), vault.WithCaPath(""))
client.SetToken(testdata.Vault.Token())
keyValue := client.KVv1()
keyValueTestSuite := new(KVv1TestSuite)
keyValueTestSuite.client = keyValue
suite.Run(t, keyValueTestSuite)
}
}
func (s *KVv1TestSuite) TestCreateAndRead() {
testKeyValues := make(map[string]string)
testKeyValues["PrivateKey"] = "abcde"
err := s.client.Create("9697fdce-39df-45ac-9115-5e3913c34613", testKeyValues)
require.NoError(s.T(), err)
readResponse, readErr := s.client.Read("9697fdce-39df-45ac-9115-5e3913c34613")
require.NoError(s.T(), readErr)
require.Equal(s.T(), readResponse.Data, testKeyValues)
}
func (s *KVv1TestSuite) TestOverwriteAndRead() {
testKeyValues := make(map[string]string)
testKeyValues["PrivateKey"] = "abcde"
testKeyValues["PrivateKey2"] = "fghji"
err := s.client.Create("9697fdce-39df-45ac-9115-5e3913c34613", testKeyValues)
require.NoError(s.T(), err)
testKeyValuesNew := make(map[string]string)
testKeyValuesNew["PrivateKey"] = "klmnop"
err = s.client.Create("9697fdce-39df-45ac-9115-5e3913c34613", testKeyValuesNew)
require.NoError(s.T(), err)
readResponse, readErr := s.client.Read("9697fdce-39df-45ac-9115-5e3913c34613")
require.NoError(s.T(), readErr)
require.Equal(s.T(), readResponse.Data, testKeyValuesNew)
}
func (s *KVv1TestSuite) TestCreateAndDelete() {
testKeyValues := make(map[string]string)
testKeyValues["PrivateKey"] = "abcde"
err := s.client.Create("2b7ff26d-30b7-43ba-96d5-79b4baba9b39", testKeyValues)
require.NoError(s.T(), err)
deleteErr := s.client.Delete("2b7ff26d-30b7-43ba-96d5-79b4baba9b39")
require.NoError(s.T(), deleteErr)
_, readErr := s.client.Read("2b7ff26d-30b7-43ba-96d5-79b4baba9b39")
require.Error(s.T(), readErr)
}
func (s *KVv1TestSuite) TestCreateAndList() {
testKeyValues := make(map[string]string)
testKeyValues["PrivateKey"] = "abcde"
require.NoError(s.T(), s.client.Create("foo", testKeyValues))
require.NoError(s.T(), s.client.Create("foo2", testKeyValues))
require.NoError(s.T(), s.client.Create("foo3/test", testKeyValues))
list, listErr := s.client.List("")
require.NoError(s.T(), listErr)
require.Contains(s.T(), list.Data.Keys, "foo")
require.Contains(s.T(), list.Data.Keys, "foo2")
require.Contains(s.T(), list.Data.Keys, "foo3/")
require.Len(s.T(), list.Data.Keys, 3)
nestedList, nestedListErr := s.client.List("foo3")
require.NoError(s.T(), nestedListErr)
require.Contains(s.T(), nestedList.Data.Keys, "test")
require.Len(s.T(), nestedList.Data.Keys, 1)
}