github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/machine/e2e/ssh_test.go (about)

     1  package e2e
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo"
     5  	. "github.com/onsi/gomega"
     6  	. "github.com/onsi/gomega/gexec"
     7  )
     8  
     9  var _ = Describe("podman machine ssh", func() {
    10  	var (
    11  		mb      *machineTestBuilder
    12  		testDir string
    13  	)
    14  
    15  	BeforeEach(func() {
    16  		testDir, mb = setup()
    17  	})
    18  	AfterEach(func() {
    19  		teardown(originalHomeDir, testDir, mb)
    20  	})
    21  
    22  	It("bad machine name", func() {
    23  		name := randomString(12)
    24  		ssh := sshMachine{}
    25  		session, err := mb.setName(name).setCmd(ssh).run()
    26  		Expect(err).To(BeNil())
    27  		Expect(session).To(Exit(125))
    28  		// TODO seems like stderr is not being returned; re-enabled when fixed
    29  		//Expect(session.outputToString()).To(ContainSubstring("not exist"))
    30  	})
    31  
    32  	It("ssh to non-running machine", func() {
    33  		name := randomString(12)
    34  		i := new(initMachine)
    35  		session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
    36  		Expect(err).To(BeNil())
    37  		Expect(session).To(Exit(0))
    38  
    39  		ssh := sshMachine{}
    40  		sshSession, err := mb.setName(name).setCmd(ssh).run()
    41  		Expect(err).To(BeNil())
    42  		// TODO seems like stderr is not being returned; re-enabled when fixed
    43  		//Expect(sshSession.outputToString()).To(ContainSubstring("is not running"))
    44  		Expect(sshSession).To(Exit(125))
    45  	})
    46  
    47  	It("ssh to running machine and check os-type", func() {
    48  		name := randomString(12)
    49  		i := new(initMachine)
    50  		session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withNow()).run()
    51  		Expect(err).To(BeNil())
    52  		Expect(session).To(Exit(0))
    53  
    54  		ssh := sshMachine{}
    55  		sshSession, err := mb.setName(name).setCmd(ssh.withSSHComand([]string{"cat", "/etc/os-release"})).run()
    56  		Expect(err).To(BeNil())
    57  		Expect(sshSession).To(Exit(0))
    58  		Expect(sshSession.outputToString()).To(ContainSubstring("Fedora CoreOS"))
    59  
    60  		// keep exit code
    61  		sshSession, err = mb.setName(name).setCmd(ssh.withSSHComand([]string{"false"})).run()
    62  		Expect(err).To(BeNil())
    63  		Expect(sshSession).To(Exit(1))
    64  		Expect(sshSession.outputToString()).To(Equal(""))
    65  		Expect(sshSession.errorToString()).To(Equal(""))
    66  	})
    67  })