github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/docker/build_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  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	"os"
    11  	"path/filepath"
    12  )
    13  
    14  const dockerFile = "src/github.com/kata-containers/tests/Dockerfiles/BuildTest/."
    15  
    16  var _ = Describe("build", func() {
    17  	var (
    18  		args      []string
    19  		id        string
    20  		imageName string = "test"
    21  		stdout    string
    22  		exitCode  int
    23  	)
    24  
    25  	BeforeEach(func() {
    26  		id = randomDockerName()
    27  	})
    28  
    29  	AfterEach(func() {
    30  		_, _, exitCode = dockerRmi(imageName)
    31  		Expect(exitCode).To(Equal(0))
    32  		Expect(ExistDockerContainer(id)).NotTo(BeTrue())
    33  	})
    34  
    35  	Describe("build with docker", func() {
    36  		Context("docker build env vars", func() {
    37  			It("should display env vars", func() {
    38  				gopath := os.Getenv("GOPATH")
    39  				entirePath := filepath.Join(gopath, dockerFile)
    40  				args = []string{"-t", imageName, entirePath}
    41  				_, _, exitCode = dockerBuild(args...)
    42  				Expect(exitCode).To(Equal(0))
    43  				args = []string{"--rm", "-t", "--name", id, imageName, "sh", "-c", "'env'"}
    44  				stdout, _, exitCode = dockerRun(args...)
    45  				Expect(exitCode).To(Equal(0))
    46  				Expect(stdout).To(ContainSubstring("test_env_vars"))
    47  			})
    48  		})
    49  	})
    50  })