github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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 . "github.com/onsi/gomega/ghttp" 12 ) 13 14 var _ = Describe("tasks command", func() { 15 var ( 16 appName string 17 ) 18 19 BeforeEach(func() { 20 appName = helpers.PrefixedRandomName("APP") 21 }) 22 23 Context("when --help flag is set", func() { 24 It("Displays command usage to output", func() { 25 session := helpers.CF("tasks", "--help") 26 Eventually(session).Should(Say("NAME:")) 27 Eventually(session).Should(Say(" tasks - List tasks of an app")) 28 Eventually(session).Should(Say("USAGE:")) 29 Eventually(session).Should(Say(" cf tasks APP_NAME")) 30 Eventually(session).Should(Say("SEE ALSO:")) 31 Eventually(session).Should(Say(" apps, logs, run-task, terminate-task")) 32 Eventually(session).Should(Exit(0)) 33 }) 34 }) 35 36 Context("when the environment is not setup correctly", func() { 37 It("fails with the appropriate errors", func() { 38 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "tasks", "app-name") 39 }) 40 41 Context("when the v3 api does not exist", func() { 42 var server *Server 43 44 BeforeEach(func() { 45 server = helpers.StartAndTargetServerWithoutV3API() 46 }) 47 48 AfterEach(func() { 49 server.Close() 50 }) 51 52 It("fails with error message that the minimum version is not met", func() { 53 session := helpers.CF("tasks", appName) 54 Eventually(session).Should(Say("FAILED")) 55 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.0\\.0 or higher\\.")) 56 Eventually(session).Should(Exit(1)) 57 }) 58 }) 59 }) 60 61 Context("when the environment is setup correctly", func() { 62 var ( 63 orgName string 64 spaceName string 65 ) 66 67 BeforeEach(func() { 68 orgName = helpers.NewOrgName() 69 spaceName = helpers.NewSpaceName() 70 71 setupCF(orgName, spaceName) 72 }) 73 74 AfterEach(func() { 75 helpers.LoginCF() 76 helpers.QuickDeleteOrg(orgName) 77 }) 78 79 Context("when the application does not exist", func() { 80 It("fails and outputs an app not found message", func() { 81 session := helpers.CF("tasks", appName) 82 Eventually(session).Should(Say("FAILED")) 83 Eventually(session.Err).Should(Say(fmt.Sprintf("App %s not found", appName))) 84 Eventually(session).Should(Exit(1)) 85 }) 86 }) 87 88 Context("when the application exists", func() { 89 BeforeEach(func() { 90 helpers.WithHelloWorldApp(func(appDir string) { 91 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 92 }) 93 }) 94 95 Context("when the application does not have associated tasks", func() { 96 It("displays an empty table", func() { 97 session := helpers.CF("tasks", appName) 98 Eventually(session).Should(Say(` 99 id name state start time command 100 `, 101 )) 102 Consistently(session).ShouldNot(Say("1")) 103 Eventually(session).Should(Exit(0)) 104 }) 105 }) 106 107 Context("when the application has associated tasks", func() { 108 BeforeEach(func() { 109 Eventually(helpers.CF("run-task", appName, "echo hello world")).Should(Exit(0)) 110 Eventually(helpers.CF("run-task", appName, "echo foo bar")).Should(Exit(0)) 111 }) 112 113 It("displays all the tasks in descending order", func() { 114 session := helpers.CF("tasks", appName) 115 userName, _ := helpers.GetCredentials() 116 Eventually(session).Should(Say(fmt.Sprintf("Getting tasks for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))) 117 Eventually(session).Should(Say("OK\n")) 118 Eventually(session).Should(Say(`id\s+name\s+state\s+start time\s+command 119 2\s+[a-zA-Z-0-9 ,:]+echo foo bar 120 1\s+[a-zA-Z-0-9 ,:]+echo hello world`)) 121 Eventually(session).Should(Exit(0)) 122 }) 123 124 Context("when the logged in user does not have authorization to see task commands", func() { 125 var user string 126 127 BeforeEach(func() { 128 user = helpers.NewUsername() 129 password := helpers.NewPassword() 130 Eventually(helpers.CF("create-user", user, password)).Should(Exit(0)) 131 Eventually(helpers.CF("set-space-role", user, orgName, spaceName, "SpaceAuditor")).Should(Exit(0)) 132 Eventually(helpers.CF("auth", user, password)).Should(Exit(0)) 133 Eventually(helpers.CF("target", "-o", orgName, "-s", spaceName)).Should(Exit(0)) 134 }) 135 136 It("does not display task commands", func() { 137 session := helpers.CF("tasks", appName) 138 Eventually(session).Should(Say("2\\s+[a-zA-Z-0-9 ,:]+\\[hidden\\]")) 139 Eventually(session).Should(Say("1\\s+[a-zA-Z-0-9 ,:]+\\[hidden\\]")) 140 Eventually(session).Should(Exit(0)) 141 }) 142 }) 143 }) 144 }) 145 }) 146 })