This repository was archived by the owner on Jun 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathcnab_test.go
91 lines (80 loc) · 2.72 KB
/
cnab_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
package e2e
import (
"fmt"
"path"
"testing"
"github.com/docker/app/internal/image"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
"gotest.tools/icmd"
)
func TestCallCustomStatusAction(t *testing.T) {
testCases := []struct {
name string
exitCode int
expectedOutput string
cnab string
}{
{
name: "validCustomDockerStatusAction",
exitCode: 0,
expectedOutput: "com.docker.app.status",
cnab: "cnab-with-docker-status",
},
{
name: "validCustomStandardStatusAction",
exitCode: 0,
expectedOutput: "io.cnab.status",
cnab: "cnab-with-standard-status",
},
// A CNAB bundle without standard or docker status action still can output
// some informations about the installation.
{
name: "missingCustomStatusAction",
exitCode: 0,
expectedOutput: "Name: missingCustomStatusAction",
cnab: "cnab-without-status",
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
cmd, cleanup := dockerCli.createTestCmd()
defer cleanup()
testDir := path.Join("testdata", testCase.cnab)
// Build CNAB invocation image
cmd.Command = dockerCli.Command("build", "--file", path.Join(testDir, "cnab", "build", "Dockerfile"), "--tag", fmt.Sprintf("e2e/%s:v0.1.0", testCase.cnab), testDir)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
// docker app install
cmd.Command = dockerCli.Command("app", "run", "--cnab-bundle-json", path.Join(testDir, image.BundleFilename), "--name", testCase.name)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
// docker app uninstall
defer func() {
cmd.Command = dockerCli.Command("app", "rm", testCase.name)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
}()
})
}
}
func TestCnabParameters(t *testing.T) {
cmd, cleanup := dockerCli.createTestCmd()
defer cleanup()
testDir := path.Join("testdata", "cnab-parameters")
// Build CNAB invocation image
cmd.Command = dockerCli.Command("build", "--file", path.Join(testDir, "cnab", "build", "Dockerfile"), "--tag", "e2e/cnab-parameters:v0.1.0", testDir)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
// docker app uninstall
defer func() {
cmd.Command = dockerCli.Command("app", "rm", "cnab-parameters")
icmd.RunCmd(cmd).Assert(t, icmd.Success)
}()
// docker app install
cmd.Command = dockerCli.Command("app", "run", "--cnab-bundle-json", path.Join(testDir, image.BundleFilename), "--name", "cnab-parameters",
"--set", "boolParam=true",
"--set", "stringParam=value",
"--set", "intParam=42")
result := icmd.RunCmd(cmd).Assert(t, icmd.Success)
expectedOutput := `boolParam=true
stringParam=value
intParam=42`
assert.Assert(t, is.Contains(result.Combined(), expectedOutput))
}