github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/namespace_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"os"
     5  
     6  	. "github.com/hanks177/podman/v4/test/utils"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("Podman namespaces", func() {
    13  	var (
    14  		tempdir    string
    15  		err        error
    16  		podmanTest *PodmanTestIntegration
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		tempdir, err = CreateTempDirInTempDir()
    21  		if err != nil {
    22  			os.Exit(1)
    23  		}
    24  		podmanTest = PodmanTestCreate(tempdir)
    25  		podmanTest.Setup()
    26  	})
    27  
    28  	AfterEach(func() {
    29  		podmanTest.Cleanup()
    30  		f := CurrentGinkgoTestDescription()
    31  		processTestResult(f)
    32  
    33  	})
    34  
    35  	It("podman namespace test", func() {
    36  		podman1 := podmanTest.Podman([]string{"--namespace", "test1", "run", "-d", ALPINE, "echo", "hello"})
    37  		podman1.WaitWithDefaultTimeout()
    38  		if IsRemote() {
    39  			// --namespace flag not supported in podman remote
    40  			Expect(podman1).Should(Exit(125))
    41  			Expect(podman1.ErrorToString()).To(ContainSubstring("unknown flag: --namespace"))
    42  			return
    43  		}
    44  		Expect(podman1).Should(Exit(0))
    45  
    46  		podman2 := podmanTest.Podman([]string{"--namespace", "test2", "ps", "-aq"})
    47  		podman2.WaitWithDefaultTimeout()
    48  		Expect(podman2).Should(Exit(0))
    49  		output := podman2.OutputToStringArray()
    50  		numCtrs := 0
    51  		for _, outputLine := range output {
    52  			if outputLine != "" {
    53  				numCtrs++
    54  			}
    55  		}
    56  		Expect(numCtrs).To(Equal(0))
    57  
    58  		numberOfCtrsNoNamespace := podmanTest.NumberOfContainers()
    59  		Expect(numberOfCtrsNoNamespace).To(Equal(1))
    60  	})
    61  })