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