-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator_test.go
121 lines (102 loc) · 3.14 KB
/
generator_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
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"fmt"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
var c = &Command{
Name: "mycommand",
API: "api.run.pivotal.io",
Org: "myorg",
Space: "myspace",
LoginOptions: "--sso",
}
func TestBashGeneratorMakeCfHome(t *testing.T) {
g := new(BashGenerator)
cfHome := filepath.Join(homeDir, ".fcfc", "mycommand")
expected := fmt.Sprintf(`\mkdir -p "%s"`, cfHome)
actual, err := g.MakeCfHome(c)
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestBashGeneratorLoginAlias(t *testing.T) {
g := new(BashGenerator)
cfHome := filepath.Join(homeDir, ".fcfc", "mycommand")
expected := fmt.Sprintf(`alias login-mycommand="CF_HOME=%s cf login -a api.run.pivotal.io -o myorg -s myspace --sso"`, cfHome)
actual, err := g.LoginAlias(c)
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestBashGeneratorCfAlias(t *testing.T) {
g := new(BashGenerator)
cfHome := filepath.Join(homeDir, ".fcfc", "mycommand")
expected := fmt.Sprintf(`alias mycommand="CF_HOME=%s CF_PLUGIN_HOME=~ cf"`, cfHome)
actual, err := g.CfAlias(c)
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestBashGeneratorWithCheckingFcfcDir(t *testing.T) {
g := new(BashGenerator)
fcfcHome := filepath.Join(homeDir, ".fcfc")
lines := []string{
"echo hello",
"echo world",
}
expectedFmt := `if [ ! -d "%s" -a -e "%s" ]; then
\echo %s is already exists and is not directory >&2
else
\mkdir -p "%s"
echo hello
echo world
fi
`
expected := fmt.Sprintf(expectedFmt, fcfcHome, fcfcHome, fcfcHome, fcfcHome)
actual, err := g.WithCheckingFcfcDir(fcfcHome, lines)
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestFishGeneratorMakeCfHome(t *testing.T) {
g := new(FishGenerator)
cfHome := filepath.Join(homeDir, ".fcfc", "mycommand")
expected := fmt.Sprintf(`command mkdir -p "%s"`, cfHome)
actual, err := g.MakeCfHome(c)
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestFishGeneratorLoginAlias(t *testing.T) {
g := new(FishGenerator)
cfHome := filepath.Join(homeDir, ".fcfc", "mycommand")
expected := fmt.Sprintf(`alias login-mycommand="CF_HOME=%s cf login -a api.run.pivotal.io -o myorg -s myspace --sso"`, cfHome)
actual, err := g.LoginAlias(c)
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestFishGeneratorCfAlias(t *testing.T) {
g := new(FishGenerator)
cfHome := filepath.Join(homeDir, ".fcfc", "mycommand")
expected := fmt.Sprintf(`alias mycommand="CF_HOME=%s CF_PLUGIN_HOME=~ cf"`, cfHome)
actual, err := g.CfAlias(c)
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestFishGeneratorWithCheckingFcfcDir(t *testing.T) {
g := new(FishGenerator)
fcfcHome := filepath.Join(homeDir, ".fcfc")
lines := []string{
"echo hello",
"echo world",
}
expectedFmt := `if test ! -d "%s" -a -e "%s"
command echo %s is already exists and is not directory >&2
else
command mkdir -p "%s"
echo hello
echo world
end
`
expected := fmt.Sprintf(expectedFmt, fcfcHome, fcfcHome, fcfcHome, fcfcHome)
actual, err := g.WithCheckingFcfcDir(fcfcHome, lines)
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}