-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_test.go
53 lines (43 loc) · 1.28 KB
/
list_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
package vault
import (
"reflect"
"sort"
"testing"
)
func TestList(t *testing.T) {
// Erase vault content after the test
t.Cleanup(cleanup)
masterkey := "TheMasterKey!"
// List from empty vault
names, err := List(masterkey)
if err != nil || len(names) != 0 {
t.Fatal("List from empty vault must return an empty slice")
}
// Prepare three entries to be inserted
entries := map[string]string{
"FirstSecretName": "FirstSecretContent",
"SecondSecretName": "SecondSecretContent",
"ThirdSecretName": "ThirdSecretContent",
}
// Get the entry names (keys) for future use
entryNames := []string{}
for k := range entries {
entryNames = append(entryNames, k)
}
sort.Strings(entryNames) // Sort for future comparison
// Insert all three entries into the vault
for name, secret := range entries {
if err := Insert(masterkey, name, secret); err != nil {
t.Fatal(err)
}
}
// List from non-empty vault
names, err = List(masterkey)
if err != nil || !reflect.DeepEqual(names, entryNames) {
t.Fatal("List from non-empty vault must return all names")
}
// List with an incorrect master key
if _, err := List("AnIncorrectMasterKey"); err == nil || err.Error() != "AuthFailed" {
t.Fatal("Attempt to list with an incorrect master key must return an error(AuthFailed)")
}
}