github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/isolated/scale_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  	. "github.com/onsi/gomega/gbytes"
     8  	. "github.com/onsi/gomega/gexec"
     9  )
    10  
    11  var _ = XDescribe("scale command", func() {
    12  	var (
    13  		orgName   string
    14  		spaceName string
    15  		appName   string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		orgName = helpers.NewOrgName()
    20  		spaceName = helpers.NewSpaceName()
    21  		appName = helpers.NewAppName()
    22  	})
    23  
    24  	Describe("help", func() {
    25  		When("--help flag is set", func() {
    26  			It("Displays command usage to output", func() {
    27  				session := helpers.CF("scale", "--help")
    28  
    29  				Eventually(session).Should(Say("scale - Change or view the instance count, disk space limit, and memory limit for an app"))
    30  				Eventually(session).Should(Say("USAGE:"))
    31  				Eventually(session).Should(Say("cf scale APP_NAME [-i INSTANCES] [-k DISK] [-m MEMORY] [-f]"))
    32  				Eventually(session).Should(Say("OPTIONS:"))
    33  				Eventually(session).Should(Say("-f\\s+Force restart of app without prompt"))
    34  				Eventually(session).Should(Say("-i\\s+Number of instances"))
    35  				Eventually(session).Should(Say("-k\\s+Disk limit (e.g. 256M, 1024M, 1G)"))
    36  				Eventually(session).Should(Say("-m\\s+Memory limit (e.g. 256M, 1024M, 1G)"))
    37  				Eventually(session).Should(Say("SEE ALSO:"))
    38  				Eventually(session).Should(Say("push"))
    39  				Eventually(session).Should(Exit(0))
    40  			})
    41  		})
    42  	})
    43  
    44  	When("the environment is not setup correctly", func() {
    45  		It("fails with the appropriate errors", func() {
    46  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "scale", "app-name")
    47  		})
    48  	})
    49  
    50  	When("the environment is set up correctly", func() {
    51  		var userName string
    52  
    53  		BeforeEach(func() {
    54  			helpers.SetupCF(orgName, spaceName)
    55  			userName, _ = helpers.GetCredentials()
    56  		})
    57  
    58  		AfterEach(func() {
    59  			helpers.QuickDeleteOrg(orgName)
    60  		})
    61  
    62  		When("the app name is not provided", func() {
    63  			It("tells the user that the app name is required, prints help text, and exits 1", func() {
    64  				session := helpers.CF("scale")
    65  
    66  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    67  				Eventually(session).Should(Say("NAME:"))
    68  				Eventually(session).Should(Exit(1))
    69  			})
    70  		})
    71  
    72  		When("the app does not exist", func() {
    73  			It("tells the user that the app is not found and exits 1", func() {
    74  				session := helpers.CF("scale", appName)
    75  
    76  				Eventually(session).Should(Say("FAILED"))
    77  				Eventually(session.Err).Should(Say("App '%s' not found", appName))
    78  				Eventually(session).Should(Exit(1))
    79  			})
    80  		})
    81  
    82  		When("the app does exist", func() {
    83  			var (
    84  				domainName string
    85  			)
    86  
    87  			BeforeEach(func() {
    88  				helpers.WithHelloWorldApp(func(appDir string) {
    89  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0))
    90  				})
    91  
    92  				domainName = helpers.DefaultSharedDomain()
    93  			})
    94  
    95  			AfterEach(func() {
    96  				Eventually(helpers.CF("delete", appName, "-f", "-r")).Should(Exit(0))
    97  			})
    98  
    99  			When("scaling number of instances", func() {
   100  				When("the wrong data type is provided to -i", func() {
   101  					It("outputs an error message to the user, provides help text, and exits 1", func() {
   102  						session := helpers.CF("scale", appName, "-i", "not-an-integer")
   103  						Eventually(session.Err).Should(Say("Incorrect Usage: invalid argument for flag `-i' \\(expected int\\)"))
   104  						Eventually(session).Should(Say("cf scale APP_NAME")) // help
   105  						Eventually(session).Should(Exit(1))
   106  					})
   107  				})
   108  
   109  				When("correct data is provided to -i", func() {
   110  					It("scales application to specified number of instances", func() {
   111  						session := helpers.CF("scale", appName, "-i", "2")
   112  						Eventually(session).Should(Say("Scaling app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) // help
   113  						Eventually(session).Should(Say("OK"))
   114  						Eventually(session).Should(Exit(0))
   115  					})
   116  				})
   117  			})
   118  
   119  			When("scaling memory", func() {
   120  				When("the wrong data type is provided to -m", func() {
   121  					It("outputs an error message to the user, provides help text, and exits 1", func() {
   122  						session := helpers.CF("scale", appName, "-m", "not-a-memory")
   123  						Eventually(session.Err).Should(Say("Incorrect Usage: invalid argument for flag `-m`"))
   124  						Eventually(session).Should(Say("cf scale APP_NAME")) // help
   125  						Eventually(session).Should(Exit(1))
   126  					})
   127  				})
   128  
   129  				When("correct data is provided to -m", func() {
   130  					When("-f flag is not provided", func() {
   131  						var buffer *Buffer
   132  
   133  						BeforeEach(func() {
   134  							buffer = NewBuffer()
   135  						})
   136  
   137  						When("user enters y", func() {
   138  							It("scales application to specified memory with restart", func() {
   139  								_, err := buffer.Write([]byte("y\n"))
   140  								Expect(err).NotTo(HaveOccurred())
   141  
   142  								session := helpers.CFWithStdin(buffer, "scale", appName, "-m", "256M")
   143  								Eventually(session).Should(Say("This will cause the app to restart. Are you sure you want to scale %s\\? \\[yN]]", appName))
   144  								Eventually(session).Should(Say("Scaling app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   145  								Eventually(session).Should(Say("Stopping app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   146  								Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   147  								Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   148  
   149  								Eventually(session).Should(Say("name:\\s+%s", appName))
   150  								Eventually(session).Should(Say("requested state:\\s+started"))
   151  								Eventually(session).Should(Say("instances:\\s+1/1"))
   152  								Eventually(session).Should(Say("usage:\\s+256M x 1 instances"))
   153  								Eventually(session).Should(Say("routes:\\s+%s.%s", appName, domainName))
   154  								Eventually(session).Should(Say("last uploaded:"))
   155  								Eventually(session).Should(Say("stack:\\s+cflinuxfs"))
   156  								Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack"))
   157  								Eventually(session).Should(Say("start command:"))
   158  
   159  								Eventually(session).Should(Say("state\\s+since\\s+cpu\\s+memory\\s+disk\\s+details"))
   160  								Eventually(session).Should(Say("#0\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 256M.*of 1G"))
   161  								Eventually(session).Should(Exit(0))
   162  							})
   163  						})
   164  
   165  						When("user enters n", func() {
   166  							It("does not scale the app", func() {
   167  								_, err := buffer.Write([]byte("n\n"))
   168  								Expect(err).NotTo(HaveOccurred())
   169  
   170  								session := helpers.CFWithStdin(buffer, "scale", appName, "-m", "256M")
   171  								Eventually(session).Should(Say("This will cause the app to restart. Are you sure you want to scale %s\\? \\[yN]]", appName))
   172  								Eventually(session).Should(Say("Scale cancelled"))
   173  								Eventually(session).Should(Exit(0))
   174  								session = helpers.CF("scale", appName)
   175  								Eventually(session).Should(Say("memoty:\\s+128M"))
   176  								Eventually(session).Should(Exit(0))
   177  							})
   178  						})
   179  					})
   180  
   181  					When("-f flag provided", func() {
   182  						It("scales without prompt", func() {
   183  							session := helpers.CF("scale", appName, "-m", "256M", "-f")
   184  							Eventually(session).Should(Say("Scaling app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   185  							Eventually(session).Should(Exit(0))
   186  						})
   187  					})
   188  				})
   189  			})
   190  
   191  			When("scaling disk", func() {
   192  				When("the wrong data type is provided to -k", func() {
   193  					It("outputs an error message to the user, provides help text, and exits 1", func() {
   194  						session := helpers.CF("scale", appName, "-k", "not-a-disk")
   195  						Eventually(session.Err).Should(Say("Incorrect Usage: invalid argument for flag `-k`"))
   196  						Eventually(session).Should(Say("cf scale APP_NAME")) // help
   197  						Eventually(session).Should(Exit(1))
   198  					})
   199  				})
   200  
   201  				It("scales application to specified disk with restart", func() {
   202  					session := helpers.CF("scale", appName, "-k", "512M", "-f")
   203  					Eventually(session).Should(Say("Scaling app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   204  					Eventually(session).Should(Say("Stopping app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   205  					Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   206  					Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   207  
   208  					Eventually(session).Should(Say("name:\\s+%s", appName))
   209  					Eventually(session).Should(Say("requested state:\\s+started"))
   210  					Eventually(session).Should(Say("instances:\\s+1/1"))
   211  					Eventually(session).Should(Say("usage:\\s+128M x 1 instances"))
   212  					Eventually(session).Should(Say("routes:\\s+%s.%s", appName, domainName))
   213  					Eventually(session).Should(Say("last uploaded:"))
   214  					Eventually(session).Should(Say("stack:\\s+cflinuxfs"))
   215  					Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack"))
   216  					Eventually(session).Should(Say("start command:"))
   217  
   218  					Eventually(session).Should(Say("state\\s+since\\s+cpu\\s+memory\\s+disk\\s+details"))
   219  					Eventually(session).Should(Say("#0\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 128M.*of 512M"))
   220  					Eventually(session).Should(Exit(0))
   221  				})
   222  			})
   223  
   224  			When("scaling all of them", func() {
   225  				It("scales application to specified number of instances, memory and disk with restart", func() {
   226  					session := helpers.CF("scale", appName, "-i", "2", "-m", "256M", "-k", "512M", "-f")
   227  					Eventually(session).Should(Say("Scaling app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   228  					Eventually(session).Should(Say("Stopping app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   229  					Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   230  					Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   231  
   232  					Eventually(session).Should(Say("name:\\s+%s", appName))
   233  					Eventually(session).Should(Say("requested state:\\s+started"))
   234  					Eventually(session).Should(Say("instances:\\s+2/2"))
   235  					Eventually(session).Should(Say("usage:\\s+256M x 2 instances"))
   236  					Eventually(session).Should(Say("routes:\\s+%s.%s", appName, domainName))
   237  					Eventually(session).Should(Say("last uploaded:"))
   238  					Eventually(session).Should(Say("stack:\\s+cflinuxfs"))
   239  					Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack"))
   240  					Eventually(session).Should(Say("start command:"))
   241  
   242  					Eventually(session).Should(Say("state\\s+since\\s+cpu\\s+memory\\s+disk\\s+details"))
   243  					Eventually(session).Should(Say("#0\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 256M.*of 512M"))
   244  					Eventually(session).Should(Say("#1\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 256M.*of 512M"))
   245  					Eventually(session).Should(Exit(0))
   246  				})
   247  			})
   248  
   249  			When("scaling argument is not provided", func() {
   250  				It("outputs current scaling information", func() {
   251  					session := helpers.CF("scale", appName)
   252  					Eventually(session).Should(Say("Showing current scale of app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   253  
   254  					Eventually(session).Should(Say("memory: 128M"))
   255  					Eventually(session).Should(Say("disk: 1G"))
   256  					Eventually(session).Should(Say("instances: 1"))
   257  
   258  					Eventually(session).Should(Exit(0))
   259  				})
   260  			})
   261  		})
   262  	})
   263  })