|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "path" |
| 6 | + "runtime" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "gotest.tools/assert" |
| 10 | + is "gotest.tools/assert/cmp" |
| 11 | + "gotest.tools/fs" |
| 12 | + "gotest.tools/icmd" |
| 13 | +) |
| 14 | + |
| 15 | +func TestCallCustomStatusAction(t *testing.T) { |
| 16 | + testCases := []struct { |
| 17 | + name string |
| 18 | + exitCode int |
| 19 | + expectedOutput string |
| 20 | + cnab string |
| 21 | + }{ |
| 22 | + { |
| 23 | + name: "validCustomStatusAction", |
| 24 | + exitCode: 0, |
| 25 | + expectedOutput: "Status action", |
| 26 | + cnab: "cnab-with-status", |
| 27 | + }, |
| 28 | + { |
| 29 | + name: "missingCustomStatusAction", |
| 30 | + exitCode: 1, |
| 31 | + expectedOutput: "Error: Status failed: action not defined for bundle", |
| 32 | + cnab: "cnab-without-status", |
| 33 | + }, |
| 34 | + } |
| 35 | + |
| 36 | + for _, testCase := range testCases { |
| 37 | + t.Run(testCase.name, func(t *testing.T) { |
| 38 | + tmpDir := fs.NewDir(t, t.Name()) |
| 39 | + defer tmpDir.Remove() |
| 40 | + testDir := path.Join("testdata", testCase.cnab) |
| 41 | + cmd := icmd.Cmd{ |
| 42 | + Env: []string{fmt.Sprintf("DUFFLE_HOME=%s", tmpDir.Path())}, |
| 43 | + } |
| 44 | + |
| 45 | + // We need to explicitly set the SYSTEMROOT on windows |
| 46 | + // otherwise we get the error: |
| 47 | + // "panic: failed to read random bytes: CryptAcquireContext: Provider DLL failed to initialize correctly." |
| 48 | + // See: https://github.com/golang/go/issues/25210 |
| 49 | + if runtime.GOOS == "windows" { |
| 50 | + cmd.Env = append(cmd.Env, `SYSTEMROOT=C:\WINDOWS`) |
| 51 | + } |
| 52 | + // Build CNAB invocation image |
| 53 | + cmd.Command = []string{"docker", "build", "-f", path.Join(testDir, "cnab", "build", "Dockerfile"), "-t", fmt.Sprintf("e2e/%s:v0.1.0", testCase.cnab), testDir} |
| 54 | + icmd.RunCmd(cmd).Assert(t, icmd.Success) |
| 55 | + |
| 56 | + // docker-app install |
| 57 | + cmd.Command = []string{dockerApp, "install", path.Join(testDir, "bundle.json"), "--name", testCase.name} |
| 58 | + icmd.RunCmd(cmd).Assert(t, icmd.Success) |
| 59 | + |
| 60 | + // docker-app uninstall |
| 61 | + defer func() { |
| 62 | + cmd.Command = []string{dockerApp, "uninstall", testCase.name} |
| 63 | + icmd.RunCmd(cmd).Assert(t, icmd.Success) |
| 64 | + }() |
| 65 | + |
| 66 | + // docker-app status |
| 67 | + cmd.Command = []string{dockerApp, "status", testCase.name} |
| 68 | + result := icmd.RunCmd(cmd) |
| 69 | + result.Assert(t, icmd.Expected{ExitCode: testCase.exitCode}) |
| 70 | + assert.Assert(t, is.Contains(result.Combined(), testCase.expectedOutput)) |
| 71 | + }) |
| 72 | + } |
| 73 | +} |
0 commit comments