github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/create_org_quota_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     5  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     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("create-org-quota command", func() {
    14  	var (
    15  		orgQuotaName string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		_ = helpers.LoginCF()
    20  		orgQuotaName = helpers.NewOrgQuotaName()
    21  	})
    22  
    23  	Describe("help", func() {
    24  		When("--help flag is set", func() {
    25  			It("appears in cf help -a", func() {
    26  				session := helpers.CF("help", "-a")
    27  				Eventually(session).Should(Exit(0))
    28  				Expect(session).To(HaveCommandInCategoryWithDescription("create-org-quota", "ORG ADMIN", "Define a new quota for an organization"))
    29  			})
    30  
    31  			It("Displays command usage to output", func() {
    32  				session := helpers.CF("create-org-quota", "--help")
    33  				Eventually(session).Should(Say("NAME:"))
    34  				Eventually(session).Should(Say("create-org-quota - Define a new quota for an organization"))
    35  				Eventually(session).Should(Say("USAGE:"))
    36  				Eventually(session).Should(Say(`cf create-org-quota ORG_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\] \[-l LOG_VOLUME\]`))
    37  				Eventually(session).Should(Say("ALIAS:"))
    38  				Eventually(session).Should(Say("create-quota"))
    39  				Eventually(session).Should(Say("OPTIONS:"))
    40  				Eventually(session).Should(Say(`-a\s+Total number of application instances. \(Default: unlimited\)`))
    41  				Eventually(session).Should(Say(`--allow-paid-service-plans\s+Allow provisioning instances of paid service plans. \(Default: disallowed\)`))
    42  				Eventually(session).Should(Say(`-i\s+Maximum amount of memory a process can have \(e.g. 1024M, 1G, 10G\). \(Default: unlimited\)`))
    43  				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\)`))
    44  				Eventually(session).Should(Say(`-r\s+Total number of routes. -1 represents an unlimited amount. \(Default: 0\)`))
    45  				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\)`))
    46  				Eventually(session).Should(Say(`-s\s+Total number of service instances. -1 represents an unlimited amount. \(Default: 0\)`))
    47  				Eventually(session).Should(Say(`-l\s+Total log volume per second all processes can have, in bytes \(e.g. 128B, 4K, 1M\). -1 represents an unlimited amount. \(Default: -1\)`))
    48  				Eventually(session).Should(Say("SEE ALSO:"))
    49  				Eventually(session).Should(Say("create-org, org-quotas, set-org-quota"))
    50  				Eventually(session).Should(Exit(0))
    51  			})
    52  		})
    53  	})
    54  
    55  	When("the environment is not setup correctly", func() {
    56  		It("fails with the appropriate errors", func() {
    57  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "create-org-quota", orgQuotaName)
    58  		})
    59  	})
    60  
    61  	When("the environment is set up correctly", func() {
    62  		When("the quota name is not provided", func() {
    63  			It("tells the user that the quota name is required, prints help text, and exits 1", func() {
    64  				session := helpers.CF("create-org-quota")
    65  
    66  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ORG_QUOTA_NAME` was not provided"))
    67  				Eventually(session).Should(Say("NAME:"))
    68  				Eventually(session).Should(Exit(1))
    69  			})
    70  		})
    71  
    72  		When("a nonexistent flag is provided", func() {
    73  			It("tells the user that the flag is invalid", func() {
    74  				session := helpers.CF("create-org-quota", "--nonexistent")
    75  
    76  				Eventually(session.Err).Should(Say("Incorrect Usage: unknown flag `nonexistent'"))
    77  				Eventually(session).Should(Say("NAME:"))
    78  				Eventually(session).Should(Exit(1))
    79  			})
    80  
    81  		})
    82  
    83  		When("an invalid flag value is provided", func() {
    84  			It("tells the user that the flag value is invalid", func() {
    85  				session := helpers.CF("create-org-quota", orgQuotaName,
    86  					"-a", "hello")
    87  
    88  				Eventually(session.Err).Should(Say(`Incorrect Usage: invalid integer limit \(expected int >= -1\)`))
    89  				Eventually(session).Should(Exit(1))
    90  			})
    91  		})
    92  
    93  		When("the quota does not exist", func() {
    94  			When("no flags are provided", func() {
    95  				It("creates the quota with the default values", func() {
    96  					session := helpers.CF("create-org-quota", orgQuotaName)
    97  					userName, _ := helpers.GetCredentials()
    98  					Eventually(session).Should(Say("Creating org quota %s as %s...", orgQuotaName, userName))
    99  					Eventually(session).Should(Say("OK"))
   100  					Eventually(session).Should(Exit(0))
   101  
   102  					session = helpers.CF("org-quota", orgQuotaName)
   103  					Eventually(session).Should(Say("Getting org quota %s as %s...", orgQuotaName, userName))
   104  					Eventually(session).Should(Say(`total memory:\s+0`))
   105  					Eventually(session).Should(Say(`instance memory:\s+unlimited`))
   106  					Eventually(session).Should(Say(`service instances:\s+0`))
   107  					Eventually(session).Should(Say(`paid service plans:\s+disallowed`))
   108  					Eventually(session).Should(Say(`app instances:\s+unlimited`))
   109  					Eventually(session).Should(Say(`route ports:\s+0`))
   110  					Eventually(session).Should(Exit(0))
   111  				})
   112  			})
   113  
   114  			When("all the optional flags are provided", func() {
   115  				It("creates the quota with the specified values", func() {
   116  					userName, _ := helpers.GetCredentials()
   117  					session := helpers.CF("create-org-quota", orgQuotaName,
   118  						"-a", "2",
   119  						"--allow-paid-service-plans",
   120  						"-i", "2M",
   121  						"-m", "4M",
   122  						"-r", "6",
   123  						"--reserved-route-ports", "5",
   124  						"-s", "7",
   125  					)
   126  					Eventually(session).Should(Say("Creating org quota %s as %s...", orgQuotaName, userName))
   127  					Eventually(session).Should(Say("OK"))
   128  					Eventually(session).Should(Exit(0))
   129  
   130  					session = helpers.CF("org-quota", orgQuotaName)
   131  					Eventually(session).Should(Say("Getting org quota %s as %s...", orgQuotaName, userName))
   132  					Eventually(session).Should(Say(`total memory:\s+4M`))
   133  					Eventually(session).Should(Say(`instance memory:\s+2M`))
   134  					Eventually(session).Should(Say(`routes:\s+6`))
   135  					Eventually(session).Should(Say(`service instances:\s+7`))
   136  					Eventually(session).Should(Say(`paid service plans:\s+allowed`))
   137  					Eventually(session).Should(Say(`app instances:\s+2`))
   138  					Eventually(session).Should(Say(`route ports:\s+5`))
   139  					Eventually(session).Should(Say(`log volume per second:\s+unlimited`))
   140  					Eventually(session).Should(Exit(0))
   141  				})
   142  
   143  				When("CAPI supports log rate limits", func() {
   144  					BeforeEach(func() {
   145  						helpers.SkipIfVersionLessThan(ccversion.MinVersionLogRateLimitingV3)
   146  					})
   147  
   148  					It("creates the quota with the specified values", func() {
   149  
   150  						userName, _ := helpers.GetCredentials()
   151  						session := helpers.CF("create-org-quota", orgQuotaName,
   152  							"-l", "32K",
   153  						)
   154  						Eventually(session).Should(Say("Creating org quota %s as %s...", orgQuotaName, userName))
   155  						Eventually(session).Should(Say("OK"))
   156  						Eventually(session).Should(Exit(0))
   157  
   158  						session = helpers.CF("org-quota", orgQuotaName)
   159  						Eventually(session).Should(Say(`log volume per second:\s+32K`))
   160  						Eventually(session).Should(Exit(0))
   161  					})
   162  				})
   163  			})
   164  
   165  			When("The flags are all set to -1", func() {
   166  				It("creates the quota with the specified values", func() {
   167  					userName, _ := helpers.GetCredentials()
   168  					session := helpers.CF("create-org-quota", orgQuotaName,
   169  						"-a", "-1",
   170  						"-i", "-1",
   171  						"-m", "-1",
   172  						"-r", "-1",
   173  						"-s", "-1",
   174  						"--reserved-route-ports", "-1",
   175  					)
   176  					Eventually(session).Should(Say("Creating org quota %s as %s...", orgQuotaName, userName))
   177  					Eventually(session).Should(Say("OK"))
   178  					Eventually(session).Should(Exit(0))
   179  
   180  					session = helpers.CF("org-quota", orgQuotaName)
   181  					Eventually(session).Should(Say(`total memory:\s+unlimited`))
   182  					Eventually(session).Should(Say(`instance memory:\s+unlimited`))
   183  					Eventually(session).Should(Say(`routes:\s+unlimited`))
   184  					Eventually(session).Should(Say(`service instances:\s+unlimited`))
   185  					Eventually(session).Should(Say(`app instances:\s+unlimited`))
   186  					Eventually(session).Should(Say(`route ports:\s+unlimited`))
   187  					Eventually(session).Should(Say(`log volume per second:\s+unlimited`))
   188  					Eventually(session).Should(Exit(0))
   189  				})
   190  
   191  				When("CAPI supports log rate limits", func() {
   192  					BeforeEach(func() {
   193  						helpers.SkipIfVersionLessThan(ccversion.MinVersionLogRateLimitingV3)
   194  					})
   195  
   196  					It("creates the quota with the specified values", func() {
   197  						userName, _ := helpers.GetCredentials()
   198  						session := helpers.CF("create-org-quota", orgQuotaName,
   199  							"-l", "-1",
   200  						)
   201  						Eventually(session).Should(Say("Creating org quota %s as %s...", orgQuotaName, userName))
   202  						Eventually(session).Should(Say("OK"))
   203  						Eventually(session).Should(Exit(0))
   204  
   205  						session = helpers.CF("org-quota", orgQuotaName)
   206  						Eventually(session).Should(Say(`log volume per second:\s+unlimited`))
   207  						Eventually(session).Should(Exit(0))
   208  					})
   209  				})
   210  			})
   211  		})
   212  
   213  		When("the quota already exists", func() {
   214  			BeforeEach(func() {
   215  				Eventually(helpers.CF("create-org-quota", orgQuotaName)).Should(Exit(0))
   216  			})
   217  
   218  			It("notifies the user that the quota already exists and exits 0", func() {
   219  				session := helpers.CF("create-org-quota", orgQuotaName)
   220  				userName, _ := helpers.GetCredentials()
   221  				Eventually(session).Should(Say("Creating org quota %s as %s...", orgQuotaName, userName))
   222  				Eventually(session.Err).Should(Say(`Organization Quota '%s' already exists\.`, orgQuotaName))
   223  				Eventually(session).Should(Say("OK"))
   224  				Eventually(session).Should(Exit(0))
   225  			})
   226  		})
   227  	})
   228  })