github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/isolated/tasks_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("tasks command", func() { 14 Context("when --help flag is set", func() { 15 It("Displays command usage to output", func() { 16 session := helpers.CF("tasks", "--help") 17 Eventually(session).Should(Exit(0)) 18 Expect(session.Out).To(Say("NAME:")) 19 Expect(session.Out).To(Say(" tasks - List tasks of an app")) 20 Expect(session.Out).To(Say("USAGE:")) 21 Expect(session.Out).To(Say(" cf tasks APP_NAME")) 22 Expect(session.Out).To(Say("SEE ALSO:")) 23 Expect(session.Out).To(Say(" apps, logs, run-task, terminate-task")) 24 }) 25 }) 26 Context("when the environment is not setup correctly", func() { 27 Context("when no API endpoint is set", func() { 28 BeforeEach(func() { 29 helpers.UnsetAPI() 30 }) 31 32 It("fails with no API endpoint set message", func() { 33 session := helpers.CF("run-task", "app-name", "some command") 34 Eventually(session).Should(Exit(1)) 35 Expect(session.Out).To(Say("FAILED")) 36 Expect(session.Err).To(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 37 }) 38 }) 39 40 Context("when not logged in", func() { 41 BeforeEach(func() { 42 helpers.LogoutCF() 43 }) 44 45 It("fails with not logged in message", func() { 46 session := helpers.CF("run-task", "app-name", "some command") 47 Eventually(session).Should(Exit(1)) 48 Expect(session.Out).To(Say("FAILED")) 49 Expect(session.Err).To(Say("Not logged in. Use 'cf login' to log in.")) 50 }) 51 }) 52 53 Context("when there is no org set", func() { 54 BeforeEach(func() { 55 helpers.LogoutCF() 56 helpers.LoginCF() 57 }) 58 59 It("fails with no targeted org error message", func() { 60 session := helpers.CF("run-task", "app-name", "some command") 61 Eventually(session).Should(Exit(1)) 62 Expect(session.Out).To(Say("FAILED")) 63 Expect(session.Err).To(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 64 }) 65 }) 66 67 Context("when there is no space set", func() { 68 BeforeEach(func() { 69 helpers.LogoutCF() 70 helpers.LoginCF() 71 helpers.TargetOrg(ReadOnlyOrg) 72 }) 73 74 It("fails with no space targeted error message", func() { 75 session := helpers.CF("run-task", "app-name", "some command") 76 Eventually(session).Should(Exit(1)) 77 Expect(session.Out).To(Say("FAILED")) 78 Expect(session.Err).To(Say("No space targeted, use 'cf target -s SPACE' to target a space")) 79 }) 80 }) 81 }) 82 83 Context("when the environment is setup correctly", func() { 84 var ( 85 orgName string 86 spaceName string 87 appName string 88 ) 89 90 BeforeEach(func() { 91 orgName = helpers.NewOrgName() 92 spaceName = helpers.PrefixedRandomName("SPACE") 93 appName = helpers.PrefixedRandomName("APP") 94 95 setupCF(orgName, spaceName) 96 }) 97 98 Context("when the application does not exist", func() { 99 It("fails and outputs an app not found message", func() { 100 session := helpers.CF("run-task", appName, "echo hi") 101 Eventually(session).Should(Exit(1)) 102 Expect(session.Out).To(Say("FAILED")) 103 Expect(session.Err).To(Say(fmt.Sprintf("App %s not found", appName))) 104 }) 105 }) 106 107 Context("when the application exists", func() { 108 BeforeEach(func() { 109 helpers.WithHelloWorldApp(func(appDir string) { 110 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 111 }) 112 }) 113 114 Context("when the application does not have associated tasks", func() { 115 It("displays an empty table", func() { 116 session := helpers.CF("tasks", appName) 117 Eventually(session).Should(Exit(0)) 118 Expect(session.Out).To(Say(` 119 id name state start time command 120 `, 121 )) 122 Expect(session.Out).NotTo(Say("1")) 123 }) 124 }) 125 126 Context("when the application has associated tasks", func() { 127 BeforeEach(func() { 128 Eventually(helpers.CF("run-task", appName, "echo hello world")).Should(Exit(0)) 129 Eventually(helpers.CF("run-task", appName, "echo foo bar")).Should(Exit(0)) 130 }) 131 132 It("displays all the tasks in descending order", func() { 133 session := helpers.CF("tasks", appName) 134 Eventually(session).Should(Exit(0)) 135 userName, _ := helpers.GetCredentials() 136 Expect(session.Out).To(Say(fmt.Sprintf("Getting tasks for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))) 137 Expect(session.Out).To(Say("OK\n")) 138 Expect(session.Out).To(Say(`id\s+name\s+state\s+start time\s+command 139 2\s+[a-zA-Z-0-9 ,:]+echo foo bar 140 1\s+[a-zA-Z-0-9 ,:]+echo hello world`)) 141 }) 142 143 Context("when the logged in user does not have authorization to see task commands", func() { 144 var user string 145 146 BeforeEach(func() { 147 user = helpers.RandomUsername() 148 password := helpers.RandomPassword() 149 Eventually(helpers.CF("create-user", user, password)).Should(Exit(0)) 150 Eventually(helpers.CF("set-space-role", user, orgName, spaceName, "SpaceAuditor")).Should(Exit(0)) 151 Eventually(helpers.CF("auth", user, password)).Should(Exit(0)) 152 Eventually(helpers.CF("target", "-o", orgName, "-s", spaceName)).Should(Exit(0)) 153 }) 154 155 It("does not display task commands", func() { 156 session := helpers.CF("tasks", appName) 157 Eventually(session).Should(Exit(0)) 158 Expect(session.Out).To(Say("2\\s+[a-zA-Z-0-9 ,:]+\\[hidden\\]")) 159 Expect(session.Out).To(Say("1\\s+[a-zA-Z-0-9 ,:]+\\[hidden\\]")) 160 }) 161 }) 162 }) 163 }) 164 }) 165 })