github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/docker/terminal_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  )
    11  
    12  var _ = Describe("terminal", func() {
    13  	var (
    14  		id string
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		id = randomDockerName()
    19  	})
    20  
    21  	AfterEach(func() {
    22  		Expect(RemoveDockerContainer(id)).To(BeTrue())
    23  		Expect(ExistDockerContainer(id)).NotTo(BeTrue())
    24  	})
    25  
    26  	Describe("terminal with docker", func() {
    27  		Context("TERM env variable is set when allocating a tty", func() {
    28  			It("should display the terminal's name", func() {
    29  				stdout, _, exitCode := dockerRun("--name", id, "-t", Image, "env")
    30  				Expect(exitCode).To(Equal(0))
    31  				Expect(stdout).To(MatchRegexp("TERM=" + `[[:alnum:]]`))
    32  			})
    33  		})
    34  
    35  		Context("TERM env variable is not set when not allocating a tty", func() {
    36  			It("should not display the terminal's name", func() {
    37  				stdout, _, exitCode := dockerRun("--name", id, Image, "env")
    38  				Expect(exitCode).To(Equal(0))
    39  				Expect(stdout).NotTo(ContainSubstring("TERM"))
    40  			})
    41  		})
    42  
    43  		Context("Check that pseudo tty is setup properly when allocating a tty", func() {
    44  			It("should display the pseudo tty's name", func() {
    45  				stdout, _, exitCode := dockerRun("--name", id, "-t", Image, "tty")
    46  				Expect(exitCode).To(Equal(0))
    47  				Expect(stdout).To(MatchRegexp("/dev/pts/" + `[[:alnum:]]`))
    48  			})
    49  		})
    50  	})
    51  })