github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/restart_app_instance_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/gbytes" 9 . "github.com/onsi/gomega/gexec" 10 ) 11 12 var _ = XDescribe("restart command", func() { 13 Describe("help", func() { 14 Context("when --help flag is set", func() { 15 It("Displays command usage to output", func() { 16 session := helpers.CF("restart-app-instance", "--help") 17 18 Eventually(session).Should(Say("NAME:")) 19 Eventually(session).Should(Say("restart-app-instance - Terminate the running application instance at the given index and instantiate a new instance of the application with the same index")) 20 Eventually(session).Should(Say("USAGE:")) 21 Eventually(session).Should(Say("cf restart-app-instance APP_NAME INDEX")) 22 Eventually(session).Should(Say("SEE ALSO:")) 23 Eventually(session).Should(Say("restart")) 24 Eventually(session).Should(Exit(0)) 25 }) 26 }) 27 }) 28 29 Context("when the environment is not setup correctly", func() { 30 Context("when no API endpoint is set", func() { 31 BeforeEach(func() { 32 helpers.UnsetAPI() 33 }) 34 35 It("fails with no API endpoint set message", func() { 36 session := helpers.CF("restart-app-instance", "wut", "0") 37 Eventually(session.Out).Should(Say("FAILED")) 38 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 39 Eventually(session).Should(Exit(1)) 40 }) 41 }) 42 43 Context("when not logged in", func() { 44 BeforeEach(func() { 45 helpers.LogoutCF() 46 }) 47 48 It("fails with not logged in message", func() { 49 session := helpers.CF("restart-app-instance", "wut", "0") 50 Eventually(session.Out).Should(Say("FAILED")) 51 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 52 Eventually(session).Should(Exit(1)) 53 }) 54 }) 55 56 Context("when there is no org set", func() { 57 BeforeEach(func() { 58 helpers.LogoutCF() 59 helpers.LoginCF() 60 }) 61 62 It("fails with no targeted org error message", func() { 63 session := helpers.CF("restart-app-instance", "wut", "0") 64 Eventually(session.Out).Should(Say("FAILED")) 65 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 66 Eventually(session).Should(Exit(1)) 67 }) 68 }) 69 70 Context("when there is no space set", func() { 71 BeforeEach(func() { 72 helpers.LogoutCF() 73 helpers.LoginCF() 74 helpers.TargetOrg(ReadOnlyOrg) 75 }) 76 77 It("fails with no targeted space error message", func() { 78 session := helpers.CF("restart-app-instance", "wut", "0") 79 Eventually(session.Out).Should(Say("FAILED")) 80 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space.")) 81 Eventually(session).Should(Exit(1)) 82 }) 83 }) 84 }) 85 86 Context("when the environment is set up correctly", func() { 87 var ( 88 orgName string 89 spaceName string 90 userName string 91 appName string 92 ) 93 94 BeforeEach(func() { 95 orgName = helpers.NewOrgName() 96 spaceName = helpers.NewSpaceName() 97 appName = helpers.NewAppName() 98 99 setupCF(orgName, spaceName) 100 userName, _ = helpers.GetCredentials() 101 }) 102 103 AfterEach(func() { 104 helpers.QuickDeleteOrg(orgName) 105 }) 106 107 Context("when the app does not exist", func() { 108 It("tells the user that the start is not found and exits 1", func() { 109 session := helpers.CF("restart", appName, "0") 110 111 Eventually(session.Out).Should(Say("FAILED")) 112 Eventually(session.Err).Should(Say("App %s not found", appName)) 113 Eventually(session).Should(Exit(1)) 114 }) 115 }) 116 117 Context("when the app does exist", func() { 118 BeforeEach(func() { 119 helpers.WithHelloWorldApp(func(appDir string) { 120 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 121 }) 122 123 It("restarts app instance", func() { 124 session := helpers.CF("restart", appName) 125 Eventually(session).Should(Say("Restarting instance %d of the app %s in org %s / space %s as %s\\.\\.\\.", 10, appName, orgName, spaceName, userName)) 126 Eventually(session.Out).Should(Say("OK")) 127 Eventually(session).Should(Exit(0)) 128 }) 129 }) 130 }) 131 }) 132 })