github.com/sleungcy/cli@v7.1.0+incompatible/integration/v7/isolated/create_space_quota_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("create-space-quota command", func() {
    13  	var (
    14  		userName       string
    15  		orgName        string
    16  		spaceQuotaName string
    17  	)
    18  
    19  	Describe("help", func() {
    20  		When("--help flag is set", func() {
    21  			It("appears in cf help -a", func() {
    22  				session := helpers.CF("help", "-a")
    23  				Eventually(session).Should(Exit(0))
    24  				Expect(session).To(HaveCommandInCategoryWithDescription("create-space-quota", "SPACE ADMIN", "Define a new quota for a space"))
    25  			})
    26  
    27  			It("Displays command usage to output", func() {
    28  				session := helpers.CF("create-space-quota", "--help")
    29  				Eventually(session).Should(Say("NAME:"))
    30  				Eventually(session).Should(Say("create-space-quota - Define a new quota for a space"))
    31  				Eventually(session).Should(Say("USAGE:"))
    32  				Eventually(session).Should(Say(`cf create-space-quota QUOTA \[-m TOTAL_MEMORY\] \[-i INSTANCE_MEMORY\] \[-r ROUTES\] \[-s SERVICE_INSTANCES\] \[-a APP_INSTANCES\] \[--allow-paid-service-plans\] \[--reserved-route-ports RESERVED_ROUTE_PORTS\]`))
    33  				Eventually(session).Should(Say("OPTIONS:"))
    34  				Eventually(session).Should(Say(`-a\s+Total number of application instances. \(Default: unlimited\)`))
    35  				Eventually(session).Should(Say(`--allow-paid-service-plans\s+Allow provisioning instances of paid service plans. \(Default: disallowed\)`))
    36  				Eventually(session).Should(Say(`-i\s+Maximum amount of memory a process can have \(e.g. 1024M, 1G, 10G\). \(Default: unlimited\)`))
    37  				Eventually(session).Should(Say(`-m\s+Total amount of memory all processes can have \(e.g. 1024M, 1G, 10G\). -1 represents an unlimited amount. \(Default: 0\)`))
    38  				Eventually(session).Should(Say(`-r\s+Total number of routes. -1 represents an unlimited amount. \(Default: 0\)`))
    39  				Eventually(session).Should(Say(`--reserved-route-ports\s+Maximum number of routes that may be created with ports. -1 represents an unlimited amount. \(Default: 0\)`))
    40  				Eventually(session).Should(Say(`-s\s+Total number of service instances. -1 represents an unlimited amount. \(Default: 0\)`))
    41  				Eventually(session).Should(Say("SEE ALSO:"))
    42  				Eventually(session).Should(Say("create-space, set-space-quota, space-quotas"))
    43  				Eventually(session).Should(Exit(0))
    44  			})
    45  		})
    46  	})
    47  
    48  	When("the environment is not setup correctly", func() {
    49  		It("fails with the appropriate errors", func() {
    50  			helpers.CheckEnvironmentTargetedCorrectly(true, false, orgName, "create-space-quota", spaceQuotaName)
    51  		})
    52  	})
    53  
    54  	When("the environment is set up correctly", func() {
    55  		BeforeEach(func() {
    56  			userName = helpers.LoginCF()
    57  			orgName = helpers.CreateAndTargetOrg()
    58  			spaceQuotaName = helpers.QuotaName()
    59  		})
    60  
    61  		When("the quota name is not provided", func() {
    62  			It("tells the user that the quota name is required, prints help text, and exits 1", func() {
    63  				session := helpers.CF("create-space-quota")
    64  
    65  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SPACE_QUOTA_NAME` was not provided"))
    66  				Eventually(session).Should(Say("NAME:"))
    67  				Eventually(session).Should(Exit(1))
    68  			})
    69  		})
    70  
    71  		When("a nonexistent flag is provided", func() {
    72  			It("tells the user that the flag is invalid", func() {
    73  				session := helpers.CF("create-space-quota", "--nonexistent")
    74  
    75  				Eventually(session.Err).Should(Say("Incorrect Usage: unknown flag `nonexistent'"))
    76  				Eventually(session).Should(Say("NAME:"))
    77  				Eventually(session).Should(Exit(1))
    78  			})
    79  		})
    80  
    81  		When("the quota does not exist", func() {
    82  			When("no flags are provided", func() {
    83  				It("creates the quota with the default values", func() {
    84  					session := helpers.CF("create-space-quota", spaceQuotaName)
    85  					Eventually(session).Should(Say("Creating space quota %s for org %s as %s...", spaceQuotaName, orgName, userName))
    86  					Eventually(session).Should(Say("OK"))
    87  					Eventually(session).Should(Exit(0))
    88  
    89  					session = helpers.CF("space-quota", spaceQuotaName)
    90  					Eventually(session).Should(Say("Getting space quota %s for org %s as %s...", spaceQuotaName, orgName, userName))
    91  					Eventually(session).Should(Say(`total memory:\s+0`))
    92  					Eventually(session).Should(Say(`instance memory:\s+unlimited`))
    93  					Eventually(session).Should(Say(`routes:\s+0`))
    94  					Eventually(session).Should(Say(`service instances:\s+0`))
    95  					Eventually(session).Should(Say(`paid service plans:\s+disallowed`))
    96  					Eventually(session).Should(Say(`app instances:\s+unlimited`))
    97  					Eventually(session).Should(Say(`route ports:\s+0`))
    98  					Eventually(session).Should(Exit(0))
    99  				})
   100  			})
   101  
   102  			When("all the optional flags are provided", func() {
   103  				It("creates the quota with the specified values", func() {
   104  					session := helpers.CF("create-space-quota", spaceQuotaName,
   105  						"-a", "2",
   106  						"--allow-paid-service-plans",
   107  						"-i", "3M",
   108  						"-m", "4M",
   109  						"-r", "15",
   110  						"--reserved-route-ports", "6",
   111  						"-s", "7")
   112  					Eventually(session).Should(Say("Creating space quota %s for org %s as %s...", spaceQuotaName, orgName, userName))
   113  					Eventually(session).Should(Say("OK"))
   114  					Eventually(session).Should(Exit(0))
   115  
   116  					session = helpers.CF("space-quota", spaceQuotaName)
   117  					Eventually(session).Should(Say("Getting space quota %s for org %s as %s...", spaceQuotaName, orgName, userName))
   118  					Eventually(session).Should(Say(`total memory:\s+4M`))
   119  					Eventually(session).Should(Say(`instance memory:\s+3M`))
   120  					Eventually(session).Should(Say(`routes:\s+15`))
   121  					Eventually(session).Should(Say(`service instances:\s+7`))
   122  					Eventually(session).Should(Say(`paid service plans:\s+allowed`))
   123  					Eventually(session).Should(Say(`app instances:\s+2`))
   124  					Eventually(session).Should(Say(`route ports:\s+6`))
   125  					Eventually(session).Should(Exit(0))
   126  				})
   127  			})
   128  		})
   129  
   130  		When("the quota already exists", func() {
   131  			BeforeEach(func() {
   132  				Eventually(helpers.CF("create-space-quota", spaceQuotaName)).Should(Exit(0))
   133  			})
   134  
   135  			It("notifies the user that the quota already exists and exits 0", func() {
   136  				session := helpers.CF("create-space-quota", spaceQuotaName)
   137  				Eventually(session).Should(Say("Creating space quota %s for org %s as %s...", spaceQuotaName, orgName, userName))
   138  				Eventually(session.Err).Should(Say(`Space Quota '%s' already exists\.`, spaceQuotaName))
   139  				Eventually(session).Should(Say("OK"))
   140  				Eventually(session).Should(Exit(0))
   141  			})
   142  		})
   143  	})
   144  })