github.com/containers/podman/v4@v4.9.4/pkg/machine/e2e/ssh_test.go (about) 1 package e2e_test 2 3 import ( 4 "github.com/containers/podman/v4/pkg/machine" 5 . "github.com/onsi/ginkgo/v2" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gexec" 8 ) 9 10 var _ = Describe("podman machine ssh", func() { 11 var ( 12 mb *machineTestBuilder 13 testDir string 14 ) 15 16 BeforeEach(func() { 17 testDir, mb = setup() 18 }) 19 AfterEach(func() { 20 teardown(originalHomeDir, testDir, mb) 21 }) 22 23 It("bad machine name", func() { 24 name := randomString() 25 ssh := sshMachine{} 26 session, err := mb.setName(name).setCmd(ssh).run() 27 Expect(err).ToNot(HaveOccurred()) 28 Expect(session).To(Exit(125)) 29 Expect(session.errorToString()).To(ContainSubstring("not exist")) 30 }) 31 32 It("ssh to non-running machine", func() { 33 name := randomString() 34 i := new(initMachine) 35 session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() 36 Expect(err).ToNot(HaveOccurred()) 37 Expect(session).To(Exit(0)) 38 39 ssh := sshMachine{} 40 sshSession, err := mb.setName(name).setCmd(ssh).run() 41 Expect(err).ToNot(HaveOccurred()) 42 Expect(sshSession.errorToString()).To(ContainSubstring("is not running")) 43 Expect(sshSession).To(Exit(125)) 44 }) 45 46 It("ssh to running machine and check os-type", func() { 47 wsl := testProvider.VMType() == machine.WSLVirt 48 name := randomString() 49 i := new(initMachine) 50 session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withNow()).run() 51 Expect(err).ToNot(HaveOccurred()) 52 Expect(session).To(Exit(0)) 53 54 ssh := sshMachine{} 55 sshSession, err := mb.setName(name).setCmd(ssh.withSSHCommand([]string{"cat", "/etc/os-release"})).run() 56 Expect(err).ToNot(HaveOccurred()) 57 Expect(sshSession).To(Exit(0)) 58 59 if wsl { 60 Expect(sshSession.outputToString()).To(ContainSubstring("Fedora Linux")) 61 } else { 62 Expect(sshSession.outputToString()).To(ContainSubstring("Fedora CoreOS")) 63 } 64 65 // keep exit code 66 sshSession, err = mb.setName(name).setCmd(ssh.withSSHCommand([]string{"false"})).run() 67 Expect(err).ToNot(HaveOccurred()) 68 Expect(sshSession).To(Exit(1)) 69 Expect(sshSession.outputToString()).To(Equal("")) 70 71 // WSL will often emit an error message about the ssh key and keychains 72 if !wsl { 73 Expect(sshSession.errorToString()).To(Equal("")) 74 } 75 }) 76 })