github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v6/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(`
    79  id   name   state   start time   command
    80  `,
    81  					))
    82  					Consistently(session).ShouldNot(Say("1"))
    83  					Eventually(session).Should(Exit(0))
    84  				})
    85  			})
    86  
    87  			When("the application has associated tasks", func() {
    88  				BeforeEach(func() {
    89  					Eventually(helpers.CF("run-task", appName, "echo hello world")).Should(Exit(0))
    90  					Eventually(helpers.CF("run-task", appName, "echo foo bar")).Should(Exit(0))
    91  				})
    92  
    93  				It("displays all the tasks in descending order", func() {
    94  					session := helpers.CF("tasks", appName)
    95  					userName, _ := helpers.GetCredentials()
    96  					Eventually(session).Should(Say(fmt.Sprintf("Getting tasks for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)))
    97  					Eventually(session).Should(Say("OK\n"))
    98  					Eventually(session).Should(Say(`id\s+name\s+state\s+start time\s+command
    99  2\s+[a-zA-Z-0-9 ,:]+echo foo bar
   100  1\s+[a-zA-Z-0-9 ,:]+echo hello world`))
   101  					Eventually(session).Should(Exit(0))
   102  				})
   103  
   104  				When("the logged in user does not have authorization to see task commands", func() {
   105  					var user string
   106  
   107  					BeforeEach(func() {
   108  						user = helpers.NewUsername()
   109  						password := helpers.NewPassword()
   110  						Eventually(helpers.CF("create-user", user, password)).Should(Exit(0))
   111  						Eventually(helpers.CF("set-space-role", user, orgName, spaceName, "SpaceAuditor")).Should(Exit(0))
   112  						helpers.LogoutCF()
   113  						env := map[string]string{
   114  							"CF_USERNAME": user,
   115  							"CF_PASSWORD": password,
   116  						}
   117  						Eventually(helpers.CFWithEnv(env, "auth")).Should(Exit(0))
   118  						Eventually(helpers.CF("target", "-o", orgName, "-s", spaceName)).Should(Exit(0))
   119  					})
   120  
   121  					It("does not display task commands", func() {
   122  						session := helpers.CF("tasks", appName)
   123  						Eventually(session).Should(Say(`2\s+[a-zA-Z-0-9 ,:]+\[hidden\]`))
   124  						Eventually(session).Should(Say(`1\s+[a-zA-Z-0-9 ,:]+\[hidden\]`))
   125  						Eventually(session).Should(Exit(0))
   126  					})
   127  				})
   128  			})
   129  		})
   130  	})
   131  })