-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_test.go
45 lines (36 loc) · 1.1 KB
/
read_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
package vault
import (
"reflect"
"testing"
)
func TestRead(t *testing.T) {
// Erase vault content after the test
t.Cleanup(cleanup)
masterkey := "TheMasterKey!"
// Read entries from empty vault
entries, err := read(masterkey)
if err != nil || len(entries) != 0 {
t.Fatal("Read from empty vault must return an empty map")
}
// Prepare three entries to be inserted
entries = map[string]string{
"FirstSecretName": "FirstSecretContent",
"SecondSecretName": "SecondSecretContent",
"ThirdSecretName": "ThirdSecretContent",
}
// Insert all three entries into the vault
for name, secret := range entries {
if err := Insert(masterkey, name, secret); err != nil {
t.Fatal(err)
}
}
// Read and compare the result
readEntries, err := read(masterkey)
if err != nil || !reflect.DeepEqual(entries, readEntries) {
t.Fatal("Read result must be equal to the inserted entries")
}
// Read with an incorrect master key
if _, err := read("AnIncorrectMasterKey"); err == nil || err.Error() != "AuthFailed" {
t.Fatal("Attempt to read with an incorrect master key must return an error(AuthFailed)")
}
}