github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/docker/exitcode_test.go (about)

     1  // Copyright (c) 2018 Intel Corporation
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package docker
     6  
     7  import (
     8  	"fmt"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/ginkgo/extensions/table"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  func withExitCode(exitCode, expectedExitCode int, interactive bool) TableEntry {
    16  	return Entry(fmt.Sprintf("with exit code '%d' when interactive mode is: '%t', it should exit '%d'",
    17  		exitCode, interactive, expectedExitCode), exitCode, expectedExitCode, interactive)
    18  }
    19  
    20  var _ = Describe("docker exit code", func() {
    21  	var (
    22  		args []string
    23  		id   string
    24  	)
    25  
    26  	BeforeEach(func() {
    27  		id = randomDockerName()
    28  		args = []string{"--name", id, "--rm"}
    29  	})
    30  
    31  	AfterEach(func() {
    32  		Expect(ExistDockerContainer(id)).NotTo(BeTrue())
    33  	})
    34  
    35  	DescribeTable("check exit codes",
    36  		func(exitCode, expectedExitCode int, interactive bool) {
    37  			if interactive {
    38  				args = append(args, "-i")
    39  			}
    40  			args = append(args, DebianImage, "/usr/bin/perl", "-e", fmt.Sprintf("exit %d", exitCode))
    41  			_, _, exitCode = dockerRun(args...)
    42  			Expect(exitCode).To(Equal(expectedExitCode))
    43  		},
    44  		withExitCode(0, 0, true),
    45  		withExitCode(0, 0, false),
    46  		withExitCode(1, 1, true),
    47  		withExitCode(1, 1, false),
    48  		withExitCode(55, 55, true),
    49  		withExitCode(55, 55, false),
    50  		withExitCode(-1, 255, true),
    51  		withExitCode(-1, 255, false),
    52  		withExitCode(255, 255, true),
    53  		withExitCode(255, 255, false),
    54  		withExitCode(256, 0, true),
    55  		withExitCode(256, 0, false),
    56  	)
    57  })