github.com/loafoe/cli@v7.1.0+incompatible/integration/v7/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 var ( 15 appName string 16 ) 17 18 BeforeEach(func() { 19 appName = helpers.PrefixedRandomName("APP") 20 }) 21 22 When("--help flag is set", func() { 23 It("Displays command usage to output", func() { 24 session := helpers.CF("tasks", "--help") 25 Eventually(session).Should(Say("NAME:")) 26 Eventually(session).Should(Say(" tasks - List tasks of an app")) 27 Eventually(session).Should(Say("USAGE:")) 28 Eventually(session).Should(Say(" cf tasks APP_NAME")) 29 Eventually(session).Should(Say("SEE ALSO:")) 30 Eventually(session).Should(Say(" apps, logs, run-task, terminate-task")) 31 Eventually(session).Should(Exit(0)) 32 }) 33 }) 34 35 When("the environment is not setup correctly", func() { 36 It("fails with the appropriate errors", func() { 37 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "tasks", "app-name") 38 }) 39 }) 40 41 When("the environment is setup correctly", func() { 42 var ( 43 orgName string 44 spaceName string 45 ) 46 47 BeforeEach(func() { 48 orgName = helpers.NewOrgName() 49 spaceName = helpers.NewSpaceName() 50 51 helpers.SetupCF(orgName, spaceName) 52 }) 53 54 AfterEach(func() { 55 helpers.LoginCF() 56 helpers.QuickDeleteOrg(orgName) 57 }) 58 59 When("the application does not exist", func() { 60 It("fails and outputs an app not found message", func() { 61 session := helpers.CF("tasks", appName) 62 Eventually(session).Should(Say("FAILED")) 63 Eventually(session.Err).Should(Say(fmt.Sprintf("App '%s' not found", appName))) 64 Eventually(session).Should(Exit(1)) 65 }) 66 }) 67 68 When("the application exists", func() { 69 BeforeEach(func() { 70 helpers.WithHelloWorldApp(func(appDir string) { 71 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 72 }) 73 }) 74 75 When("the application does not have associated tasks", func() { 76 It("displays an empty table", func() { 77 session := helpers.CF("tasks", appName) 78 Eventually(session).Should(Say(`No tasks found for application\.`)) 79 Consistently(session).ShouldNot(Say("1")) 80 Eventually(session).Should(Exit(0)) 81 }) 82 }) 83 84 When("the application has associated tasks", func() { 85 BeforeEach(func() { 86 Eventually(helpers.CF("run-task", appName, "--command", "echo hello world")).Should(Exit(0)) 87 Eventually(helpers.CF("run-task", appName, "--command", "echo foo bar")).Should(Exit(0)) 88 }) 89 90 It("displays all the tasks in descending order", func() { 91 session := helpers.CF("tasks", appName) 92 userName, _ := helpers.GetCredentials() 93 Eventually(session).Should(Say(fmt.Sprintf("Getting tasks for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))) 94 Eventually(session).Should(Say(`id\s+name\s+state\s+start time\s+command 95 2\s+[a-zA-Z-0-9 ,:]+echo foo bar 96 1\s+[a-zA-Z-0-9 ,:]+echo hello world`)) 97 Eventually(session).Should(Exit(0)) 98 }) 99 100 When("the logged in user does not have authorization to see task commands", func() { 101 var user string 102 103 BeforeEach(func() { 104 user = helpers.NewUsername() 105 password := helpers.NewPassword() 106 Eventually(helpers.CF("create-user", user, password)).Should(Exit(0)) 107 Eventually(helpers.CF("set-space-role", user, orgName, spaceName, "SpaceAuditor")).Should(Exit(0)) 108 helpers.LogoutCF() 109 env := map[string]string{ 110 "CF_USERNAME": user, 111 "CF_PASSWORD": password, 112 } 113 Eventually(helpers.CFWithEnv(env, "auth")).Should(Exit(0)) 114 Eventually(helpers.CF("target", "-o", orgName, "-s", spaceName)).Should(Exit(0)) 115 }) 116 117 It("does not display task commands", func() { 118 session := helpers.CF("tasks", appName) 119 Eventually(session).Should(Say(`2\s+[a-zA-Z-0-9 ,:]+\[hidden\]`)) 120 Eventually(session).Should(Say(`1\s+[a-zA-Z-0-9 ,:]+\[hidden\]`)) 121 Eventually(session).Should(Exit(0)) 122 }) 123 }) 124 }) 125 }) 126 }) 127 })