Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 0a44934

Browse files
author
Matthieu Nottale
committed
e2e: Factor running commands in assertCommand and assertCommandOutput.
Signed-off-by: Matthieu Nottale <[email protected]>
1 parent 4d8a762 commit 0a44934

File tree

1 file changed

+21
-51
lines changed

1 file changed

+21
-51
lines changed

e2e/binary_test.go

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ func binExt() string {
7171
return ""
7272
}
7373

74+
// Run command, assert it succeeds, return its output
75+
func assertCommand(t *testing.T, exe string, args ...string) []byte {
76+
cmd := exec.Command(exe, args...)
77+
output, err := cmd.CombinedOutput()
78+
assert.NilError(t, err, string(output))
79+
return output
80+
}
81+
82+
func assertCommandOutput(t *testing.T, goldenFile string, cmd string, args ...string) {
83+
output := assertCommand(t, cmd, args...)
84+
golden.Assert(t, string(output), goldenFile)
85+
}
86+
7487
func TestRenderBinary(t *testing.T) {
7588
getBinary(t)
7689
apps, err := ioutil.ReadDir("render")
@@ -151,12 +164,7 @@ targets:
151164
"-m", "bob",
152165
"-m", "joe:[email protected]",
153166
}
154-
cmd := exec.Command(dockerApp, args...)
155-
output, err := cmd.CombinedOutput()
156-
if err != nil {
157-
fmt.Println(output)
158-
}
159-
assert.NilError(t, err)
167+
assertCommand(t, dockerApp, args...)
160168
manifest := fs.Expected(
161169
t,
162170
fs.WithMode(0755),
@@ -179,26 +187,15 @@ targets:
179187
"-m", "joe:[email protected]",
180188
"-s",
181189
}
182-
cmd = exec.Command(dockerApp, args...)
183-
output, err = cmd.CombinedOutput()
184-
if err != nil {
185-
fmt.Println(string(output))
186-
}
187-
assert.NilError(t, err)
190+
assertCommand(t, dockerApp, args...)
188191
defer os.Remove("tac.dockerapp")
189192
appData, _ := ioutil.ReadFile("tac.dockerapp")
190193
golden.Assert(t, string(appData), "init-singlefile.dockerapp")
191194
}
192195

193196
func TestInspectBinary(t *testing.T) {
194197
dockerApp, _ := getBinary(t)
195-
cmd := exec.Command(dockerApp, "inspect", "render/envvariables")
196-
output, err := cmd.CombinedOutput()
197-
if err != nil {
198-
fmt.Println(string(output))
199-
}
200-
assert.NilError(t, err)
201-
golden.Assert(t, string(output), "envvariables-inspect.golden")
198+
assertCommandOutput(t, "envvariables-inspect.golden", dockerApp, "inspect", "render/envvariables")
202199
}
203200

204201
func TestPackBinary(t *testing.T) {
@@ -235,12 +232,7 @@ func TestPackBinary(t *testing.T) {
235232

236233
func TestHelmBinary(t *testing.T) {
237234
dockerApp, _ := getBinary(t)
238-
cmd := exec.Command(dockerApp, "helm", "helm", "-s", "myapp.nginx_version=2")
239-
output, err := cmd.CombinedOutput()
240-
if err != nil {
241-
fmt.Println(string(output))
242-
}
243-
assert.NilError(t, err)
235+
assertCommand(t, dockerApp, "helm", "helm", "-s", "myapp.nginx_version=2")
244236
chart, _ := ioutil.ReadFile("helm.chart/Chart.yaml")
245237
values, _ := ioutil.ReadFile("helm.chart/values.yaml")
246238
stack, _ := ioutil.ReadFile("helm.chart/templates/stack.yaml")
@@ -255,34 +247,12 @@ func TestSplitMergeBinary(t *testing.T) {
255247
t.Skip("experimental mode needed for this test")
256248
}
257249
app := "render/envvariables"
258-
cmd := exec.Command(dockerApp, "merge", app, "-o", "remerged.dockerapp")
259-
output, err := cmd.CombinedOutput()
260-
if err != nil {
261-
fmt.Println(string(output))
262-
}
263-
assert.NilError(t, err)
250+
assertCommand(t, dockerApp, "merge", app, "-o", "remerged.dockerapp")
264251
defer os.Remove("remerged.dockerapp")
265252
// test that inspect works on single-file
266-
cmd = exec.Command(dockerApp, "inspect", "remerged")
267-
output, err = cmd.CombinedOutput()
268-
if err != nil {
269-
fmt.Println(string(output))
270-
}
271-
assert.NilError(t, err)
272-
golden.Assert(t, string(output), "envvariables-inspect.golden")
253+
assertCommandOutput(t, "envvariables-inspect.golden", dockerApp, "inspect", "remerged")
273254
// split it
274-
cmd = exec.Command(dockerApp, "split", "remerged", "-o", "splitted.dockerapp")
275-
output, err = cmd.CombinedOutput()
276-
if err != nil {
277-
fmt.Println(string(output))
278-
}
279-
assert.NilError(t, err)
255+
assertCommand(t, dockerApp, "split", "remerged", "-o", "splitted.dockerapp")
280256
defer os.RemoveAll("splitted.dockerapp")
281-
cmd = exec.Command(dockerApp, "inspect", "splitted")
282-
output, err = cmd.CombinedOutput()
283-
if err != nil {
284-
fmt.Println(string(output))
285-
}
286-
assert.NilError(t, err)
287-
golden.Assert(t, string(output), "envvariables-inspect.golden")
257+
assertCommandOutput(t, "envvariables-inspect.golden", dockerApp, "inspect", "splitted")
288258
}

0 commit comments

Comments
 (0)