github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v6/isolated/run_task_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("run-task command", func() {
    14  	When("--help flag is set", func() {
    15  		It("Displays command usage to output", func() {
    16  			session := helpers.CF("run-task", "--help")
    17  			Eventually(session).Should(Say("NAME:"))
    18  			Eventually(session).Should(Say("   run-task - Run a one-off task on an app"))
    19  			Eventually(session).Should(Say("USAGE:"))
    20  			Eventually(session).Should(Say(`   cf run-task APP_NAME COMMAND \[-k DISK] \[-m MEMORY\] \[--name TASK_NAME\]`))
    21  			Eventually(session).Should(Say("TIP:"))
    22  			Eventually(session).Should(Say("   Use 'cf logs' to display the logs of the app and all its tasks. If your task name is unique, grep this command's output for the task name to view task-specific logs."))
    23  			Eventually(session).Should(Say("EXAMPLES:"))
    24  			Eventually(session).Should(Say(`   cf run-task my-app "bundle exec rake db:migrate" --name migrate`))
    25  			Eventually(session).Should(Say("ALIAS:"))
    26  			Eventually(session).Should(Say("   rt"))
    27  			Eventually(session).Should(Say("OPTIONS:"))
    28  			Eventually(session).Should(Say(`   -k          Disk limit \(e\.g\. 256M, 1024M, 1G\)`))
    29  			Eventually(session).Should(Say(`   -m          Memory limit \(e\.g\. 256M, 1024M, 1G\)`))
    30  			Eventually(session).Should(Say(`   --name      Name to give the task \(generated if omitted\)`))
    31  			Eventually(session).Should(Say("SEE ALSO:"))
    32  			Eventually(session).Should(Say("   logs, tasks, terminate-task"))
    33  			Eventually(session).Should(Exit(0))
    34  		})
    35  	})
    36  
    37  	When("the environment is not setup correctly", func() {
    38  		It("fails with the appropriate errors", func() {
    39  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "run-task", "app-name", "some-command")
    40  		})
    41  	})
    42  
    43  	When("the environment is setup correctly", func() {
    44  		var (
    45  			orgName   string
    46  			spaceName string
    47  			appName   string
    48  		)
    49  
    50  		BeforeEach(func() {
    51  			orgName = helpers.NewOrgName()
    52  			spaceName = helpers.NewSpaceName()
    53  			appName = helpers.PrefixedRandomName("APP")
    54  
    55  			helpers.SetupCF(orgName, spaceName)
    56  		})
    57  
    58  		AfterEach(func() {
    59  			helpers.QuickDeleteOrg(orgName)
    60  		})
    61  
    62  		When("the application exists", func() {
    63  			BeforeEach(func() {
    64  				helpers.WithHelloWorldApp(func(appDir string) {
    65  					Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0))
    66  				})
    67  			})
    68  
    69  			When("the task name is not provided", func() {
    70  				It("creates a new task", func() {
    71  					session := helpers.CF("run-task", appName, "echo hi")
    72  					userName, _ := helpers.GetCredentials()
    73  					Eventually(session).Should(Say("Creating task for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
    74  					Eventually(session).Should(Say("OK"))
    75  					Eventually(session).Should(Say("Task has been submitted successfully for execution."))
    76  					Eventually(session).Should(Say(`task name:\s+.+`))
    77  					Eventually(session).Should(Say(`task id:\s+1`))
    78  					Eventually(session).Should(Exit(0))
    79  				})
    80  			})
    81  
    82  			When("the task name is provided", func() {
    83  				It("creates a new task with the provided name", func() {
    84  					session := helpers.CF("run-task", appName, "echo hi", "--name", "some-task-name")
    85  					userName, _ := helpers.GetCredentials()
    86  					Eventually(session).Should(Say("Creating task for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
    87  					Eventually(session).Should(Say("OK"))
    88  					Eventually(session).Should(Say("Task has been submitted successfully for execution."))
    89  					Eventually(session).Should(Say(`task name:\s+some-task-name`))
    90  					Eventually(session).Should(Say(`task id:\s+1`))
    91  					Eventually(session).Should(Exit(0))
    92  
    93  					taskSession := helpers.CF("tasks", appName)
    94  					Eventually(taskSession).Should(Say(`1\s+some-task-name`))
    95  					Eventually(taskSession).Should(Exit(0))
    96  				})
    97  			})
    98  
    99  			When("disk space is provided", func() {
   100  				When("the provided disk space is invalid", func() {
   101  					It("displays error and exits 1", func() {
   102  						session := helpers.CF("run-task", appName, "echo hi", "-k", "invalid")
   103  						Eventually(session.Err).Should(Say("Byte quantity must be an integer with a unit of measurement like M, MB, G, or GB"))
   104  
   105  						Eventually(session).Should(Exit(1))
   106  					})
   107  				})
   108  
   109  				When("the provided disk space is valid", func() {
   110  					It("runs the task with the provided disk space", func() {
   111  						diskSpace := 123
   112  						session := helpers.CF("run-task", appName, "echo hi", "-k", fmt.Sprintf("%dM", diskSpace))
   113  						Eventually(session).Should(Exit(0))
   114  
   115  						session = helpers.CF("tasks", appName, "-v")
   116  						Eventually(session).Should(Say("\"disk_in_mb\": %d", diskSpace))
   117  						Eventually(session).Should(Exit(0))
   118  					})
   119  				})
   120  			})
   121  
   122  			When("task memory is provided", func() {
   123  				When("the provided memory is invalid", func() {
   124  					It("displays error and exits 1", func() {
   125  						session := helpers.CF("run-task", appName, "echo hi", "-m", "invalid")
   126  						Eventually(session.Err).Should(Say("Byte quantity must be an integer with a unit of measurement like M, MB, G, or GB"))
   127  						Eventually(session).Should(Exit(1))
   128  					})
   129  				})
   130  
   131  				When("the provided memory is valid", func() {
   132  					It("runs the task with the provided memory", func() {
   133  						taskMemory := 123
   134  						session := helpers.CF("run-task", appName, "echo hi", "-m", fmt.Sprintf("%dM", taskMemory))
   135  						Eventually(session).Should(Exit(0))
   136  
   137  						session = helpers.CF("tasks", appName, "-v")
   138  						Eventually(session).Should(Say("\"memory_in_mb\": %d", taskMemory))
   139  						Eventually(session).Should(Exit(0))
   140  					})
   141  				})
   142  			})
   143  		})
   144  
   145  		When("the application is not staged", func() {
   146  			BeforeEach(func() {
   147  				helpers.WithHelloWorldApp(func(appDir string) {
   148  					Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0))
   149  				})
   150  			})
   151  
   152  			It("fails and outputs task must have a droplet message", func() {
   153  				session := helpers.CF("run-task", appName, "echo hi")
   154  				Eventually(session).Should(Say("FAILED"))
   155  				Eventually(session.Err).Should(Say(`Error running task: App is not staged.`))
   156  				Eventually(session).Should(Exit(1))
   157  			})
   158  		})
   159  
   160  		When("the application is staged but stopped", func() {
   161  			BeforeEach(func() {
   162  				helpers.WithHelloWorldApp(func(appDir string) {
   163  					Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0))
   164  				})
   165  				session := helpers.CF("stop", appName)
   166  				Eventually(session).Should(Exit(0))
   167  			})
   168  
   169  			It("creates a new task", func() {
   170  				session := helpers.CF("run-task", appName, "echo hi")
   171  				userName, _ := helpers.GetCredentials()
   172  				Eventually(session).Should(Say("Creating task for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   173  				Eventually(session).Should(Say("OK"))
   174  				Eventually(session).Should(Say("Task has been submitted successfully for execution."))
   175  				Eventually(session).Should(Say(`task name:\s+.+`))
   176  				Eventually(session).Should(Say(`task id:\s+1`))
   177  				Eventually(session).Should(Exit(0))
   178  			})
   179  		})
   180  
   181  		When("the application does not exist", func() {
   182  			It("fails and outputs an app not found message", func() {
   183  				session := helpers.CF("run-task", appName, "echo hi")
   184  				Eventually(session).Should(Say("FAILED"))
   185  				Eventually(session.Err).Should(Say(fmt.Sprintf("App '%s' not found", appName)))
   186  				Eventually(session).Should(Exit(1))
   187  			})
   188  		})
   189  	})
   190  })