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

     1  package integration
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  
     7  	"github.com/containers/common/pkg/config"
     8  	. "github.com/hanks177/podman/v4/test/utils"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("podman image scp", func() {
    15  	ConfPath := struct {
    16  		Value string
    17  		IsSet bool
    18  	}{}
    19  	var (
    20  		tempdir    string
    21  		podmanTest *PodmanTestIntegration
    22  	)
    23  
    24  	BeforeEach(func() {
    25  
    26  		ConfPath.Value, ConfPath.IsSet = os.LookupEnv("CONTAINERS_CONF")
    27  		conf, err := ioutil.TempFile("", "containersconf")
    28  		if err != nil {
    29  			panic(err)
    30  		}
    31  		os.Setenv("CONTAINERS_CONF", conf.Name())
    32  		tempdir, err = CreateTempDirInTempDir()
    33  		if err != nil {
    34  			os.Exit(1)
    35  		}
    36  		podmanTest = PodmanTestCreate(tempdir)
    37  		podmanTest.Setup()
    38  	})
    39  
    40  	AfterEach(func() {
    41  		podmanTest.Cleanup()
    42  
    43  		os.Remove(os.Getenv("CONTAINERS_CONF"))
    44  		if ConfPath.IsSet {
    45  			os.Setenv("CONTAINERS_CONF", ConfPath.Value)
    46  		} else {
    47  			os.Unsetenv("CONTAINERS_CONF")
    48  		}
    49  		f := CurrentGinkgoTestDescription()
    50  		processTestResult(f)
    51  
    52  	})
    53  
    54  	It("podman image scp bogus image", func() {
    55  		if IsRemote() {
    56  			Skip("this test is only for non-remote")
    57  		}
    58  		scp := podmanTest.Podman([]string{"image", "scp", "FOOBAR"})
    59  		scp.WaitWithDefaultTimeout()
    60  		Expect(scp).To(ExitWithError())
    61  	})
    62  
    63  	It("podman image scp with proper connection", func() {
    64  		if IsRemote() {
    65  			Skip("this test is only for non-remote")
    66  		}
    67  		cmd := []string{"system", "connection", "add",
    68  			"--default",
    69  			"QA",
    70  			"ssh://root@server.fubar.com:2222/run/podman/podman.sock",
    71  		}
    72  		session := podmanTest.Podman(cmd)
    73  		session.WaitWithDefaultTimeout()
    74  		Expect(session).To(Exit(0))
    75  
    76  		cfg, err := config.ReadCustomConfig()
    77  		Expect(err).ShouldNot(HaveOccurred())
    78  		Expect(cfg.Engine).To(HaveField("ActiveService", "QA"))
    79  		Expect(cfg.Engine.ServiceDestinations).To(HaveKeyWithValue("QA",
    80  			config.Destination{
    81  				URI: "ssh://root@server.fubar.com:2222/run/podman/podman.sock",
    82  			},
    83  		))
    84  
    85  		scp := podmanTest.Podman([]string{"image", "scp", ALPINE, "QA::"})
    86  		scp.Wait(45)
    87  		// exit with error because we cannot make an actual ssh connection
    88  		// This tests that the input we are given is validated and prepared correctly
    89  		// The error given should either be a missing image (due to testing suite complications) or a i/o timeout on ssh
    90  		Expect(scp).To(ExitWithError())
    91  
    92  	})
    93  
    94  })