-
Notifications
You must be signed in to change notification settings - Fork 30
/
remove_test.go
46 lines (41 loc) · 957 Bytes
/
remove_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
package main
import (
"testing"
"github.com/miquella/vaulted/lib"
)
func TestRemove(t *testing.T) {
store := NewTestStore()
store.Vaults["one"] = &vaulted.Vault{}
store.Vaults["two"] = &vaulted.Vault{}
CaptureStdout(func() {
r := Remove{
VaultNames: []string{"one"},
}
err := r.Run(store)
if err != nil {
t.Fatal(err)
}
})
if store.VaultExists("one") {
t.Fatal("The vault 'one' was not removed")
}
CaptureStdout(func() {
r := Remove{
VaultNames: []string{"one", "two", "three"},
}
err := r.Run(store)
if err == nil {
t.Fatal("Expected an error removing 'one' and 'three', but was successful instead")
}
exiterr, ok := err.(ErrorWithExitCode)
if !ok {
t.Fatalf("Expected ErrorWithExitCode, got %#v", err)
}
if exiterr.ExitCode != 2 {
t.Fatalf("Expected ExitCode: 2, got ExitCode: %v", exiterr.ExitCode)
}
})
if store.VaultExists("two") {
t.Fatal("Still expected 'two' to be removed")
}
}