-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathinfo_test.go
73 lines (55 loc) · 1.35 KB
/
info_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
package commands
import (
"kool-dev/kool/core/builder"
"kool-dev/kool/core/environment"
"kool-dev/kool/core/shell"
"strings"
"testing"
"github.com/spf13/cobra"
)
func setupInfoTest(f *KoolInfo) {
f.envStorage.Set("KOOL_FILTER_TESTING", "1")
f.envStorage.Set("KOOL_TESTING", "1")
}
func fakeKoolInfo() *KoolInfo {
return &KoolInfo{
*(newDefaultKoolService().Fake()),
environment.NewFakeEnvStorage(),
&builder.FakeCommand{},
&builder.FakeCommand{},
}
}
func TestInfo(t *testing.T) {
f := fakeKoolInfo()
setupInfoTest(f)
output, err := execInfoCommand(NewInfoCmd(f), f)
if err != nil {
t.Fatal(err)
}
for _, expected := range []string{"KOOL_FILTER_TESTING=1", "KOOL_TESTING=1"} {
if !strings.Contains(output, expected) {
t.Errorf("Expected '%s', got '%s'", expected, output)
}
}
}
func TestFilteredInfo(t *testing.T) {
f := fakeKoolInfo()
setupInfoTest(f)
cmd := NewInfoCmd(f)
cmd.SetArgs([]string{"FILTER"})
output, err := execInfoCommand(cmd, f)
if err != nil {
t.Fatal(err)
}
expected := "KOOL_FILTER_TESTING=1"
if !strings.Contains(output, expected) {
t.Errorf("Expected '%s', got '%s'", expected, output)
}
}
func execInfoCommand(cmd *cobra.Command, f *KoolInfo) (output string, err error) {
if err = cmd.Execute(); err != nil {
return
}
output = strings.Join(f.shell.(*shell.FakeShell).OutLines, "\n")
return
}