-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_test.go
66 lines (54 loc) · 1.95 KB
/
update_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
package vault
import (
"testing"
)
func TestUpdate(t *testing.T) {
// Erase vault content after the test
t.Cleanup(cleanup)
masterkey := "TheMasterKey!"
// Update something from empty vault
if err := Update(masterkey, "Something", "Whatever"); err == nil || err.Error() != "NotFound" {
t.Fatal("Update something in an empty vault must return an error(NotFound)")
}
// 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)
}
}
// Update a non-existent entry in the non-empty vault
if err := Update(masterkey, "UnicornEgg", "Whatever"); err == nil || err.Error() != "NotFound" {
t.Fatal("Update of a non-existent entry must return an error(NotFound)")
}
// Update an existing entry with an incorrect master key
if err := Update("AnIncorrectMasterKey", "FirstSecretName", "Whatever"); err == nil || err.Error() != "AuthFailed" {
t.Fatal("Attempt to update with an incorrect master key must return an error(AuthFailed)")
}
// Update a non-existing entry with an incorrect master key
if err := Update("AnIncorrectMasterKey", "UnicornEgg", "Whatever"); err == nil || err.Error() != "AuthFailed" {
t.Fatal("Attempt to update with an incorrect master key must return an error(AuthFailed)")
}
// Update all three entries by appending "Updated" to the end
for name, secret := range entries {
err := Update(masterkey, name, secret+"Updated")
if err != nil {
t.Fatal(err)
}
}
// Fetch and compare all three entries
for name, secret := range entries {
fetchedSecret, err := Fetch(masterkey, name)
if err != nil {
t.Fatal(err)
}
if fetchedSecret != secret+"Updated" {
t.Fatalf("Expected %qUpdated, got %q", secret, fetchedSecret)
}
}
}