-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcommand_set_fixtures.go
201 lines (176 loc) · 5.15 KB
/
command_set_fixtures.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package fixtures
import (
"github.com/gopinath-langote/1build/testing/def"
"github.com/gopinath-langote/1build/testing/utils"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
)
func featureSetTestsData() []Test {
feature := "set"
return []Test{
shouldSetNewCommand(feature),
shouldSetNewCommandInSpecifiedFile(feature),
shouldUpdateExistingCommand(feature),
shouldFailWhenConfigurationFileIsNotFound(feature),
shouldFailWhenConfigurationFileIsInInvalidFormat(feature),
shouldSetBeforeCommand(feature),
shouldSetAfterCommand(feature),
}
}
func shouldSetNewCommand(feature string) Test {
defaultFileContent := `
project: Sample Project
commands:
- build: go build
`
expectedOutput := `project: Sample Project
commands:
- build: go build
- Test: go Test
`
return Test{
Feature: feature,
Name: "shouldSetNewCommand",
CmdArgs: Args("set", "Test", "go Test"),
Setup: func(dir string) error {
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
content, _ := ioutil.ReadFile(filePath)
return assert.Contains(t, string(content), expectedOutput)
},
}
}
func shouldSetNewCommandInSpecifiedFile(feature string) Test {
defaultFileContent := `
project: Sample Project
commands:
- build: go build
`
expectedOutput := `project: Sample Project
commands:
- build: go build
- Test: go Test
`
return Test{
Feature: feature,
Name: "shouldSetNewCommandInSpecifiedFile",
CmdArgs: func(dir string) []string {
return []string{"set", "Test", "go Test", "-f", dir + "/some-dir/some-config.yaml"}
},
Setup: func(dir string) error {
_ = os.MkdirAll(dir+"/some-dir", 0750)
return utils.CreateConfigFileWithName(dir+"/some-dir", "some-config.yaml", defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/some-dir/some-config.yaml"
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)
return assert.Contains(t, string(content), expectedOutput)
},
}
}
func shouldUpdateExistingCommand(feature string) Test {
defaultFileContent := `
project: Sample Project
commands:
- build: go build
`
expectedOutput := `project: Sample Project
commands:
- build: go build -o
`
return Test{
Feature: feature,
Name: "shouldUpdateExistingCommand",
CmdArgs: Args("set", "build", "go build -o"),
Setup: func(dir string) error {
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
content, _ := ioutil.ReadFile(filePath)
return assert.Contains(t, string(content), expectedOutput)
},
}
}
func shouldFailWhenConfigurationFileIsNotFound(feature string) Test {
return Test{
Feature: feature,
Name: "shouldFailWhenConfigurationFileIsNotFound",
CmdArgs: Args("set", "build", "go build -o"),
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
return assert.Contains(t, actualOutput, "no '"+def.ConfigFileName+"' file found")
},
}
}
func shouldFailWhenConfigurationFileIsInInvalidFormat(feature string) Test {
return Test{
Feature: feature,
Name: "shouldFailWhenConfigurationFileIsInInvalidFormat",
CmdArgs: Args("set", "build", "go build"),
Setup: func(dir string) error {
return utils.CreateConfigFile(dir, "invalid config content")
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
return assert.Contains(t, actualOutput, "Unable to parse '"+def.ConfigFileName+"' config file. Make sure file is in correct format.")
},
}
}
func shouldSetBeforeCommand(feature string) Test {
defaultFileContent := `
project: Sample Project
commands:
- build: go build
`
expectedOutput := `project: Sample Project
after: yo
commands:
- build: go build
`
return Test{
Feature: feature,
Name: "shouldSetBeforeCommand",
CmdArgs: Args("set", "after", "yo"),
Setup: func(dir string) error {
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
content, _ := ioutil.ReadFile(filePath)
return assert.Contains(t, string(content), expectedOutput)
},
}
}
func shouldSetAfterCommand(feature string) Test {
defaultFileContent := `
project: Sample Project
commands:
- build: go build
`
expectedOutput := `project: Sample Project
after: yo
commands:
- build: go build
`
return Test{
Feature: feature,
Name: "shouldSetBeforeCommand",
CmdArgs: Args("set", "after", "yo"),
Setup: func(dir string) error {
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
content, _ := ioutil.ReadFile(filePath)
return assert.Contains(t, string(content), expectedOutput)
},
}
}