-
Notifications
You must be signed in to change notification settings - Fork 30
/
copy_test.go
71 lines (59 loc) · 1.29 KB
/
copy_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
package main
import (
"testing"
"github.com/miquella/vaulted/lib"
)
func TestCopy(t *testing.T) {
store := NewTestStore()
store.Vaults["old"] = &vaulted.Vault{
Vars: map[string]string{
"TEST": "SUCCESSFUL",
},
}
store.Passwords["old"] = "one old password"
c := Copy{
OldVaultName: "old",
NewVaultName: "new",
}
err := c.Run(store)
if err != nil {
t.Fatal(err)
}
v, ok := store.Vaults["new"]
if !ok {
t.Fatal("The vault was not copied")
}
if v.Vars == nil || v.Vars["TEST"] != "SUCCESSFUL" {
t.Fatal("The vault contents were not copied")
}
if store.Passwords["old"] == store.Passwords["new"] {
t.Fatal("Passwords should be different, but aren't!")
}
}
func TestCopyToSelf(t *testing.T) {
store := NewTestStore()
store.Vaults["one"] = &vaulted.Vault{
Vars: map[string]string{
"TEST": "SUCCESSFUL",
},
}
store.Passwords["one"] = "one old password"
c := Copy{
OldVaultName: "one",
NewVaultName: "one",
}
err := c.Run(store)
if err != nil {
t.Fatal(err)
}
v, ok := store.Vaults["one"]
if !ok {
t.Fatal("The vault was not preserved")
}
if v.Vars == nil || v.Vars["TEST"] != "SUCCESSFUL" {
t.Fatal("The vault contents were not preserved")
}
if store.Passwords["one"] == "one old password" {
t.Fatal("Passwords should be different, but aren't!")
}
}