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

Commit cadefc2

Browse files
Add e2e tests:
- split/merge a single file with CRLF - render a single file with documents in random order Signed-off-by: Silvin Lubecki <[email protected]>
1 parent 0e3bc32 commit cadefc2

File tree

5 files changed

+95
-22
lines changed

5 files changed

+95
-22
lines changed

e2e/commands_test.go

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package e2e
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"io/ioutil"
8+
"path"
79
"path/filepath"
810
"regexp"
911
"strings"
@@ -207,37 +209,80 @@ func TestDetectApp(t *testing.T) {
207209
})
208210
}
209211

212+
func patchEndOfLine(t *testing.T, eol []byte, name, fromDir, toDir string) {
213+
buf := golden.Get(t, filepath.Join(fromDir, name))
214+
bytes.ReplaceAll(buf, []byte{'\n'}, eol)
215+
assert.NilError(t, ioutil.WriteFile(filepath.Join(toDir, name), buf, 0644))
216+
}
217+
210218
func TestSplitMerge(t *testing.T) {
211-
cmd, cleanup := dockerCli.createTestCmd()
212-
defer cleanup()
219+
testCases := []struct {
220+
name string
221+
lineEnding []byte
222+
}{
223+
{
224+
name: "without-crlf",
225+
lineEnding: []byte{'\n'},
226+
},
227+
{
228+
name: "with-crlf",
229+
lineEnding: []byte{'\r', '\n'},
230+
},
231+
}
232+
for _, test := range testCases {
233+
t.Run(test.name, func(t *testing.T) {
234+
cmd, cleanup := dockerCli.createTestCmd()
235+
defer cleanup()
213236

214-
tmpDir := fs.NewDir(t, "split_merge")
215-
defer tmpDir.Remove()
237+
tmpDir := fs.NewDir(t, "split_merge", fs.WithDir("my.dockerapp"))
238+
defer tmpDir.Remove()
216239

217-
cmd.Command = dockerCli.Command("app", "merge", "testdata/render/envvariables/my.dockerapp", "--output", tmpDir.Join("remerged.dockerapp"))
218-
icmd.RunCmd(cmd).Assert(t, icmd.Success)
240+
inputDir := filepath.Join("render", "envvariables", "my.dockerapp")
241+
testDataDir := tmpDir.Join("my.dockerapp")
219242

220-
cmd.Dir = tmpDir.Path()
243+
// replace the line ending from the versioned test data files and put them to a temp dir
244+
for _, name := range internal.FileNames {
245+
patchEndOfLine(t, test.lineEnding, name, inputDir, testDataDir)
246+
}
221247

222-
// test that inspect works on single-file
223-
cmd.Command = dockerCli.Command("app", "inspect", "remerged")
224-
result := icmd.RunCmd(cmd).Assert(t, icmd.Success)
225-
golden.Assert(t, result.Combined(), "envvariables-inspect.golden")
248+
// Merge a multi-files app to a single-file app
249+
cmd.Command = dockerCli.Command("app", "merge", testDataDir, "--output", tmpDir.Join("remerged.dockerapp"))
250+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
226251

227-
// split it
228-
cmd.Command = dockerCli.Command("app", "split", "remerged", "--output", "split.dockerapp")
229-
icmd.RunCmd(cmd).Assert(t, icmd.Success)
252+
cmd.Dir = tmpDir.Path()
230253

231-
cmd.Command = dockerCli.Command("app", "inspect", "remerged")
232-
result = icmd.RunCmd(cmd).Assert(t, icmd.Success)
233-
golden.Assert(t, result.Combined(), "envvariables-inspect.golden")
254+
// test that inspect works on single-file
255+
cmd.Command = dockerCli.Command("app", "inspect", "remerged")
256+
result := icmd.RunCmd(cmd).Assert(t, icmd.Success)
257+
golden.Assert(t, result.Combined(), "envvariables-inspect.golden")
234258

235-
// test inplace
236-
cmd.Command = dockerCli.Command("app", "merge", "split")
237-
icmd.RunCmd(cmd).Assert(t, icmd.Success)
259+
// split it
260+
cmd.Command = dockerCli.Command("app", "split", "remerged", "--output", "split.dockerapp")
261+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
238262

239-
cmd.Command = dockerCli.Command("app", "split", "split")
240-
icmd.RunCmd(cmd).Assert(t, icmd.Success)
263+
// test that inspect still works
264+
cmd.Command = dockerCli.Command("app", "inspect", "remerged")
265+
result = icmd.RunCmd(cmd).Assert(t, icmd.Success)
266+
golden.Assert(t, result.Combined(), "envvariables-inspect.golden")
267+
268+
// the split app must be the same as the original one
269+
manifest := fs.Expected(
270+
t,
271+
fs.WithMode(0755),
272+
fs.WithFile(internal.MetadataFileName, string(golden.Get(t, path.Join(testDataDir, internal.MetadataFileName))), fs.WithMode(0644)),
273+
fs.WithFile(internal.ComposeFileName, string(golden.Get(t, path.Join(testDataDir, internal.ComposeFileName))), fs.WithMode(0644)),
274+
fs.WithFile(internal.ParametersFileName, string(golden.Get(t, path.Join(testDataDir, internal.ParametersFileName))), fs.WithMode(0644)),
275+
)
276+
assert.Assert(t, fs.Equal(tmpDir.Join("split.dockerapp"), manifest))
277+
278+
// test inplace
279+
cmd.Command = dockerCli.Command("app", "merge", "split")
280+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
281+
282+
cmd.Command = dockerCli.Command("app", "split", "split")
283+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
284+
})
285+
}
241286
}
242287

243288
func TestBundle(t *testing.T) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
myapp.command3: bam
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "3.4"
2+
services:
3+
test:
4+
command:
5+
- bash
6+
- -c
7+
- cat bar bam
8+
image: alpine:latest
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3.4"
2+
services:
3+
test:
4+
image: alpine:latest
5+
command: bash -c "${myapp.command1} ${myapp.command2} ${myapp.command3}"
6+
---
7+
myapp:
8+
command1: cat
9+
command2: foo
10+
command3: bar
11+
---
12+
version: 0.1.0
13+
name: myapp
14+
maintainers:
15+
- name: dev
16+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
myapp:
2+
command2: bar
3+
command3: baz

0 commit comments

Comments
 (0)