github.com/containers/podman/v4@v4.9.4/test/e2e/image_scp_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/containers/common/pkg/config"
     8  	. "github.com/containers/podman/v4/test/utils"
     9  	"github.com/containers/storage/pkg/homedir"
    10  	. "github.com/onsi/ginkgo/v2"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("podman image scp", func() {
    15  
    16  	BeforeEach(setupEmptyContainersConf)
    17  
    18  	It("podman image scp bogus image", func() {
    19  		scp := podmanTest.Podman([]string{"image", "scp", "FOOBAR"})
    20  		scp.WaitWithDefaultTimeout()
    21  		Expect(scp).Should(ExitWithError())
    22  	})
    23  
    24  	It("podman image scp with proper connection", func() {
    25  		if _, err := os.Stat(filepath.Join(homedir.Get(), ".ssh", "known_hosts")); err != nil {
    26  			Skip("known_hosts does not exist or is not accessible")
    27  		}
    28  		cmd := []string{"system", "connection", "add",
    29  			"--default",
    30  			"QA",
    31  			"ssh://root@podman.test:2222/run/podman/podman.sock",
    32  		}
    33  		session := podmanTest.Podman(cmd)
    34  		session.WaitWithDefaultTimeout()
    35  		Expect(session).Should(ExitCleanly())
    36  
    37  		cfg, err := config.ReadCustomConfig()
    38  		Expect(err).ShouldNot(HaveOccurred())
    39  		Expect(cfg.Engine).Should(HaveField("ActiveService", "QA"))
    40  		Expect(cfg.Engine.ServiceDestinations).To(HaveKeyWithValue("QA",
    41  			config.Destination{
    42  				URI: "ssh://root@podman.test:2222/run/podman/podman.sock",
    43  			},
    44  		))
    45  
    46  		scp := podmanTest.Podman([]string{"image", "scp", ALPINE, "QA::"})
    47  		scp.WaitWithDefaultTimeout()
    48  		// exit with error because we cannot make an actual ssh connection
    49  		// This tests that the input we are given is validated and prepared correctly
    50  		// The error given should either be a missing image (due to testing suite complications) or a no such host timeout on ssh
    51  		Expect(scp).Should(ExitWithError())
    52  		// podman-remote exits with a different error
    53  		if !IsRemote() {
    54  			Expect(scp.ErrorToString()).Should(ContainSubstring("no such host"))
    55  		}
    56  
    57  	})
    58  
    59  })