forked from miquella/vaulted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_test.go
109 lines (98 loc) · 1.94 KB
/
env_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"os"
"testing"
"github.com/miquella/vaulted/lib"
)
var (
envFishOutput = `set -x ONE "111111";
set -x THREE "333";
set -x TWO "222";
`
envFishOutputWithHint = `# To load these variables into your shell, execute:
# eval (vaulted env one)
set -x ONE "111111";
set -x THREE "333";
set -x TWO "222";
`
envShOutput = `export ONE="111111"
export THREE="333"
export TWO="222"
`
envShOutputWithHint = `# To load these variables into your shell, execute:
# eval $(vaulted env one)
export ONE="111111"
export THREE="333"
export TWO="222"
`
)
func TestEng(t *testing.T) {
steward := NewTestSteward()
steward.Vaults["one"] = &vaulted.Vault{
Vars: map[string]string{
"TWO": "222",
"ONE": "111111",
"THREE": "333",
},
}
output := CaptureStdout(func() {
e := Env{
VaultName: "one",
Shell: "fish",
}
err := e.Run(steward)
if err != nil {
t.Fatal(err)
}
})
if string(output) != envFishOutput {
t.Fatalf("Incorrect output: %s", output)
}
output = CaptureStdout(func() {
args := os.Args
os.Args = []string{"vaulted", "env", "one"}
defer func() { os.Args = args }()
e := Env{
VaultName: "one",
Shell: "fish",
UsageHint: true,
}
err := e.Run(steward)
if err != nil {
t.Fatal(err)
}
})
if string(output) != envFishOutputWithHint {
t.Fatalf("Incorrect output: %s", output)
}
output = CaptureStdout(func() {
e := Env{
VaultName: "one",
Shell: "sh",
}
err := e.Run(steward)
if err != nil {
t.Fatal(err)
}
})
if string(output) != envShOutput {
t.Fatalf("Incorrect output: %s", output)
}
output = CaptureStdout(func() {
args := os.Args
os.Args = []string{"vaulted", "env", "one"}
defer func() { os.Args = args }()
e := Env{
VaultName: "one",
Shell: "sh",
UsageHint: true,
}
err := e.Run(steward)
if err != nil {
t.Fatal(err)
}
})
if string(output) != envShOutputWithHint {
t.Fatalf("Incorrect output: %s", output)
}
}