github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/e2e/cnab_test.go (about)

     1  package e2e
     2  
     3  import (
     4  	"fmt"
     5  	"path"
     6  	"testing"
     7  
     8  	"github.com/docker/app/internal/image"
     9  	"gotest.tools/assert"
    10  	is "gotest.tools/assert/cmp"
    11  	"gotest.tools/icmd"
    12  )
    13  
    14  func TestCallCustomStatusAction(t *testing.T) {
    15  	testCases := []struct {
    16  		name           string
    17  		exitCode       int
    18  		expectedOutput string
    19  		cnab           string
    20  	}{
    21  		{
    22  			name:           "validCustomDockerStatusAction",
    23  			exitCode:       0,
    24  			expectedOutput: "com.docker.app.status",
    25  			cnab:           "cnab-with-docker-status",
    26  		},
    27  		{
    28  			name:           "validCustomStandardStatusAction",
    29  			exitCode:       0,
    30  			expectedOutput: "io.cnab.status",
    31  			cnab:           "cnab-with-standard-status",
    32  		},
    33  		// A CNAB bundle without standard or docker status action still can output
    34  		// some informations about the installation.
    35  		{
    36  			name:           "missingCustomStatusAction",
    37  			exitCode:       0,
    38  			expectedOutput: "Name:        missingCustomStatusAction",
    39  			cnab:           "cnab-without-status",
    40  		},
    41  	}
    42  
    43  	for _, testCase := range testCases {
    44  		t.Run(testCase.name, func(t *testing.T) {
    45  			cmd, cleanup := dockerCli.createTestCmd()
    46  			defer cleanup()
    47  			testDir := path.Join("testdata", testCase.cnab)
    48  
    49  			// Build CNAB invocation image
    50  			cmd.Command = dockerCli.Command("build", "--file", path.Join(testDir, "cnab", "build", "Dockerfile"), "--tag", fmt.Sprintf("e2e/%s:v0.1.0", testCase.cnab), testDir)
    51  			icmd.RunCmd(cmd).Assert(t, icmd.Success)
    52  
    53  			// docker app install
    54  			cmd.Command = dockerCli.Command("app", "run", "--cnab-bundle-json", path.Join(testDir, image.BundleFilename), "--name", testCase.name)
    55  			icmd.RunCmd(cmd).Assert(t, icmd.Success)
    56  
    57  			// docker app uninstall
    58  			defer func() {
    59  				cmd.Command = dockerCli.Command("app", "rm", testCase.name)
    60  				icmd.RunCmd(cmd).Assert(t, icmd.Success)
    61  			}()
    62  		})
    63  	}
    64  }
    65  
    66  func TestCnabParameters(t *testing.T) {
    67  	cmd, cleanup := dockerCli.createTestCmd()
    68  	defer cleanup()
    69  	testDir := path.Join("testdata", "cnab-parameters")
    70  
    71  	// Build CNAB invocation image
    72  	cmd.Command = dockerCli.Command("build", "--file", path.Join(testDir, "cnab", "build", "Dockerfile"), "--tag", "e2e/cnab-parameters:v0.1.0", testDir)
    73  	icmd.RunCmd(cmd).Assert(t, icmd.Success)
    74  
    75  	// docker app uninstall
    76  	defer func() {
    77  		cmd.Command = dockerCli.Command("app", "rm", "cnab-parameters")
    78  		icmd.RunCmd(cmd).Assert(t, icmd.Success)
    79  	}()
    80  
    81  	// docker app install
    82  	cmd.Command = dockerCli.Command("app", "run", "--cnab-bundle-json", path.Join(testDir, image.BundleFilename), "--name", "cnab-parameters",
    83  		"--set", "boolParam=true",
    84  		"--set", "stringParam=value",
    85  		"--set", "intParam=42")
    86  	result := icmd.RunCmd(cmd).Assert(t, icmd.Success)
    87  	expectedOutput := `boolParam=true
    88  stringParam=value
    89  intParam=42`
    90  	assert.Assert(t, is.Contains(result.Combined(), expectedOutput))
    91  }