github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/ssh_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "path/filepath" 8 9 "code.cloudfoundry.org/cli/integration/helpers" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/gbytes" 13 . "github.com/onsi/gomega/gexec" 14 ) 15 16 var _ = Describe("ssh command", func() { 17 Describe("help", func() { 18 Context("when --help flag is provided", func() { 19 It("displays command usage to output", func() { 20 session := helpers.CF("ssh", "--help") 21 Eventually(session.Out).Should(Say(`NAME:`)) 22 Eventually(session.Out).Should(Say(`ssh - SSH to an application container instance`)) 23 Eventually(session.Out).Should(Say(`USAGE:`)) 24 Eventually(session.Out).Should(Say(`cf ssh APP_NAME \[-i INDEX\] \[-c COMMAND\]\.\.\. \[-L \[BIND_ADDRESS:\]PORT:HOST:HOST_PORT\] \[--skip-host-validation\] \[--skip-remote-execution\] \[--disable-pseudo-tty \| --force-pseudo-tty \| --request-pseudo-tty\]`)) 25 Eventually(session.Out).Should(Say(`--app-instance-index, -i\s+Application instance index \(Default: 0\)`)) 26 Eventually(session.Out).Should(Say(`--command, -c\s+Command to run\. This flag can be defined more than once\.`)) 27 Eventually(session.Out).Should(Say(`--disable-pseudo-tty, -T\s+Disable pseudo-tty allocation`)) 28 Eventually(session.Out).Should(Say(`--force-pseudo-tty\s+Force pseudo-tty allocation`)) 29 Eventually(session.Out).Should(Say(`-L\s+Local port forward specification\. This flag can be defined more than once\.`)) 30 Eventually(session.Out).Should(Say(`--request-pseudo-tty, -t\s+Request pseudo-tty allocation`)) 31 Eventually(session.Out).Should(Say(`--skip-host-validation, -k\s+Skip host key validation`)) 32 Eventually(session.Out).Should(Say(`--skip-remote-execution, -N\s+Do not execute a remote command`)) 33 Eventually(session.Out).Should(Say(`SEE ALSO:`)) 34 Eventually(session.Out).Should(Say(`allow-space-ssh, enable-ssh, space-ssh-allowed, ssh-code, ssh-enabled`)) 35 Eventually(session).Should(Exit(0)) 36 }) 37 }) 38 }) 39 40 Context("when an application with multiple instances has been pushed", func() { 41 var ( 42 appName string 43 appDirForCleanup string 44 domainName string 45 orgName string 46 spaceName string 47 tcpDomain helpers.Domain 48 ) 49 50 BeforeEach(func() { 51 helpers.LogoutCF() 52 53 orgName = helpers.NewOrgName() 54 spaceName = helpers.NewSpaceName() 55 56 setupCF(orgName, spaceName) 57 appName = helpers.PrefixedRandomName("app") 58 domainName = defaultSharedDomain() 59 tcpDomain = helpers.NewDomain(orgName, helpers.DomainName("tcp")) 60 tcpDomain.CreateWithRouterGroup("default-tcp") 61 helpers.WithHelloWorldApp(func(appDir string) { 62 manifestContents := []byte(fmt.Sprintf(` 63 --- 64 applications: 65 - name: %s 66 memory: 128M 67 instances: 2 68 disk_quota: 128M 69 routes: 70 - route: %s.%s 71 - route: %s:0 72 `, appName, appName, domainName, tcpDomain.Name)) 73 manifestPath := filepath.Join(appDir, "manifest.yml") 74 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 75 Expect(err).ToNot(HaveOccurred()) 76 77 // Create manifest 78 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack", "--random-route")).Should(Exit(0)) 79 appDirForCleanup = appDir 80 }) 81 }) 82 83 AfterEach(func() { 84 Eventually(helpers.CF("delete", appName, "-f", "-r")).Should(Exit(0)) 85 Expect(os.RemoveAll(appDirForCleanup)).NotTo(HaveOccurred()) 86 helpers.QuickDeleteOrg(orgName) 87 }) 88 89 Context("when the app index is specified", func() { 90 Context("when it is negative", func() { 91 It("throws an error and informs the user that the app instance index cannot be negative", func() { 92 session := helpers.CF("ssh", appName, "-i", "-1") 93 Eventually(session.Out).Should(Say("FAILED")) 94 Eventually(session.Out).Should(Say("The application instance index cannot be negative")) 95 Eventually(session).Should(Exit(1)) 96 }) 97 }) 98 99 Context("when the app index exceeds the last valid index", func() { 100 It("throws an error and informs the user that the specified application does not exist", func() { 101 session := helpers.CF("ssh", appName, "-i", "2") 102 Eventually(session.Out).Should(Say("FAILED")) 103 Eventually(session.Out).Should(Say("The specified application instance does not exist")) 104 Eventually(session).Should(Exit(1)) 105 }) 106 }) 107 108 Context("when it is a valid index", func() { 109 It("does not throw any error", func() { 110 buffer := NewBuffer() 111 buffer.Write([]byte("exit\n")) 112 session := helpers.CFWithStdin(buffer, "ssh", appName, "-i", "0") 113 Eventually(session).Should(Exit(0)) 114 }) 115 }) 116 }) 117 }) 118 })