github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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  								buffer.Write([]byte("y\n"))
   140  								session := helpers.CFWithStdin(buffer, "scale", appName, "-m", "256M")
   141  								Eventually(session).Should(Say("This will cause the app to restart. Are you sure you want to scale %s\\? \\[yN]]", appName))
   142  								Eventually(session).Should(Say("Scaling app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   143  								Eventually(session).Should(Say("Stopping app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   144  								Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   145  								Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   146  
   147  								Eventually(session).Should(Say("name:\\s+%s", appName))
   148  								Eventually(session).Should(Say("requested state:\\s+started"))
   149  								Eventually(session).Should(Say("instances:\\s+1/1"))
   150  								Eventually(session).Should(Say("usage:\\s+256M x 1 instances"))
   151  								Eventually(session).Should(Say("routes:\\s+%s.%s", appName, domainName))
   152  								Eventually(session).Should(Say("last uploaded:"))
   153  								Eventually(session).Should(Say("stack:\\s+cflinuxfs"))
   154  								Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack"))
   155  								Eventually(session).Should(Say("start command:"))
   156  
   157  								Eventually(session).Should(Say("state\\s+since\\s+cpu\\s+memory\\s+disk\\s+details"))
   158  								Eventually(session).Should(Say("#0\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 256M.*of 1G"))
   159  								Eventually(session).Should(Exit(0))
   160  							})
   161  						})
   162  
   163  						When("user enters n", func() {
   164  							It("does not scale the app", func() {
   165  								buffer.Write([]byte("n\n"))
   166  								session := helpers.CFWithStdin(buffer, "scale", appName, "-m", "256M")
   167  								Eventually(session).Should(Say("This will cause the app to restart. Are you sure you want to scale %s\\? \\[yN]]", appName))
   168  								Eventually(session).Should(Say("Scale cancelled"))
   169  								Eventually(session).Should(Exit(0))
   170  								session = helpers.CF("scale", appName)
   171  								Eventually(session).Should(Say("memoty:\\s+128M"))
   172  								Eventually(session).Should(Exit(0))
   173  							})
   174  						})
   175  					})
   176  
   177  					When("-f flag provided", func() {
   178  						It("scales without prompt", func() {
   179  							session := helpers.CF("scale", appName, "-m", "256M", "-f")
   180  							Eventually(session).Should(Say("Scaling app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   181  							Eventually(session).Should(Exit(0))
   182  						})
   183  					})
   184  				})
   185  			})
   186  
   187  			When("scaling disk", func() {
   188  				When("the wrong data type is provided to -k", func() {
   189  					It("outputs an error message to the user, provides help text, and exits 1", func() {
   190  						session := helpers.CF("scale", appName, "-k", "not-a-disk")
   191  						Eventually(session.Err).Should(Say("Incorrect Usage: invalid argument for flag `-k`"))
   192  						Eventually(session).Should(Say("cf scale APP_NAME")) // help
   193  						Eventually(session).Should(Exit(1))
   194  					})
   195  				})
   196  
   197  				It("scales application to specified disk with restart", func() {
   198  					session := helpers.CF("scale", appName, "-k", "512M", "-f")
   199  					Eventually(session).Should(Say("Scaling app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   200  					Eventually(session).Should(Say("Stopping app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   201  					Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   202  					Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   203  
   204  					Eventually(session).Should(Say("name:\\s+%s", appName))
   205  					Eventually(session).Should(Say("requested state:\\s+started"))
   206  					Eventually(session).Should(Say("instances:\\s+1/1"))
   207  					Eventually(session).Should(Say("usage:\\s+128M x 1 instances"))
   208  					Eventually(session).Should(Say("routes:\\s+%s.%s", appName, domainName))
   209  					Eventually(session).Should(Say("last uploaded:"))
   210  					Eventually(session).Should(Say("stack:\\s+cflinuxfs"))
   211  					Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack"))
   212  					Eventually(session).Should(Say("start command:"))
   213  
   214  					Eventually(session).Should(Say("state\\s+since\\s+cpu\\s+memory\\s+disk\\s+details"))
   215  					Eventually(session).Should(Say("#0\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 128M.*of 512M"))
   216  					Eventually(session).Should(Exit(0))
   217  				})
   218  			})
   219  
   220  			When("scaling all of them", func() {
   221  				It("scales application to specified number of instances, memory and disk with restart", func() {
   222  					session := helpers.CF("scale", appName, "-i", "2", "-m", "256M", "-k", "512M", "-f")
   223  					Eventually(session).Should(Say("Scaling app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   224  					Eventually(session).Should(Say("Stopping app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   225  					Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   226  					Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   227  
   228  					Eventually(session).Should(Say("name:\\s+%s", appName))
   229  					Eventually(session).Should(Say("requested state:\\s+started"))
   230  					Eventually(session).Should(Say("instances:\\s+2/2"))
   231  					Eventually(session).Should(Say("usage:\\s+256M x 2 instances"))
   232  					Eventually(session).Should(Say("routes:\\s+%s.%s", appName, domainName))
   233  					Eventually(session).Should(Say("last uploaded:"))
   234  					Eventually(session).Should(Say("stack:\\s+cflinuxfs"))
   235  					Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack"))
   236  					Eventually(session).Should(Say("start command:"))
   237  
   238  					Eventually(session).Should(Say("state\\s+since\\s+cpu\\s+memory\\s+disk\\s+details"))
   239  					Eventually(session).Should(Say("#0\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 256M.*of 512M"))
   240  					Eventually(session).Should(Say("#1\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 256M.*of 512M"))
   241  					Eventually(session).Should(Exit(0))
   242  				})
   243  			})
   244  
   245  			When("scaling argument is not provided", func() {
   246  				It("outputs current scaling information", func() {
   247  					session := helpers.CF("scale", appName)
   248  					Eventually(session).Should(Say("Showing current scale of app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   249  
   250  					Eventually(session).Should(Say("memory: 128M"))
   251  					Eventually(session).Should(Say("disk: 1G"))
   252  					Eventually(session).Should(Say("instances: 1"))
   253  
   254  					Eventually(session).Should(Exit(0))
   255  				})
   256  			})
   257  		})
   258  	})
   259  })