github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/test/e2e/export_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	. "github.com/containers/podman/v2/test/utils"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("Podman export", 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  		podmanTest.SeedImages()
    27  	})
    28  
    29  	AfterEach(func() {
    30  		podmanTest.Cleanup()
    31  		f := CurrentGinkgoTestDescription()
    32  		processTestResult(f)
    33  
    34  	})
    35  
    36  	It("podman export output flag", func() {
    37  		_, ec, cid := podmanTest.RunLsContainer("")
    38  		Expect(ec).To(Equal(0))
    39  
    40  		outfile := filepath.Join(podmanTest.TempDir, "container.tar")
    41  		result := podmanTest.Podman([]string{"export", "-o", outfile, cid})
    42  		result.WaitWithDefaultTimeout()
    43  		Expect(result.ExitCode()).To(Equal(0))
    44  		_, err := os.Stat(outfile)
    45  		Expect(err).To(BeNil())
    46  
    47  		err = os.Remove(outfile)
    48  		Expect(err).To(BeNil())
    49  	})
    50  
    51  	It("podman container export output flag", func() {
    52  		_, ec, cid := podmanTest.RunLsContainer("")
    53  		Expect(ec).To(Equal(0))
    54  
    55  		outfile := filepath.Join(podmanTest.TempDir, "container.tar")
    56  		result := podmanTest.Podman([]string{"container", "export", "-o", outfile, cid})
    57  		result.WaitWithDefaultTimeout()
    58  		Expect(result.ExitCode()).To(Equal(0))
    59  		_, err := os.Stat(outfile)
    60  		Expect(err).To(BeNil())
    61  
    62  		err = os.Remove(outfile)
    63  		Expect(err).To(BeNil())
    64  	})
    65  
    66  	It("podman export bad filename", func() {
    67  		_, ec, cid := podmanTest.RunLsContainer("")
    68  		Expect(ec).To(Equal(0))
    69  
    70  		outfile := filepath.Join(podmanTest.TempDir, "container:with:colon.tar")
    71  		result := podmanTest.Podman([]string{"export", "-o", outfile, cid})
    72  		result.WaitWithDefaultTimeout()
    73  		Expect(result).To(ExitWithError())
    74  	})
    75  })