github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/update_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/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("update-org-quota command", func() {
    13  	Describe("help", func() {
    14  		When("--help flag is set", func() {
    15  			It("Displays command usage to output", func() {
    16  				session := helpers.CF("update-org-quota", "--help")
    17  				Eventually(session).Should(Say("NAME:"))
    18  				Eventually(session).Should(Say("update-org-quota - Update an existing organization quota"))
    19  				Eventually(session).Should(Say("USAGE:"))
    20  				Eventually(session).Should(Say(`cf update-org-quota QUOTA [-m TOTAL_MEMORY] [-i INSTANCE_MEMORY] \[-n NEW_NAME\] \[-r ROUTES\] \[-s SERVICE_INSTANCES\] \[-a APP_INSTANCES\] \[--allow-paid-service-plans | --disallow-paid-service-plans\] \[--reserved-route-ports RESERVED_ROUTE_PORTS\] \[-l LOG_VOLUME\]`))
    21  				Eventually(session).Should(Say("ALIAS:"))
    22  				Eventually(session).Should(Say("update-quota"))
    23  				Eventually(session).Should(Say("OPTIONS:"))
    24  				Eventually(session).Should(Say(`-a\s+Total number of application instances. -1 represents an unlimited amount.`))
    25  				Eventually(session).Should(Say(`--allow-paid-service-plans\s+Allow provisioning instances of paid service plans.`))
    26  				Eventually(session).Should(Say(`--disallow-paid-service-plans\s+Disallow provisioning instances of paid service plans.`))
    27  				Eventually(session).Should(Say(`-i\s+Maximum amount of memory a process can have \(e.g. 1024M, 1G, 10G\). -1 represents an unlimited amount.`))
    28  				Eventually(session).Should(Say(`-m\s+Total amount of memory all processes can have \(e.g. 1024M, 1G, 10G\).  -1 represents an unlimited amount.`))
    29  				Eventually(session).Should(Say(`-n\s+New name`))
    30  				Eventually(session).Should(Say(`-r\s+Total number of routes. -1 represents an unlimited amount.`))
    31  				Eventually(session).Should(Say(`--reserved-route-ports\s+Maximum number of routes that may be created with ports. -1 represents an unlimited amount.`))
    32  				Eventually(session).Should(Say(`-s\s+Total number of service instances. -1 represents an unlimited amount.`))
    33  				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.`))
    34  				Eventually(session).Should(Say("SEE ALSO:"))
    35  				Eventually(session).Should(Say("org, org-quota"))
    36  				Eventually(session).Should(Exit(0))
    37  			})
    38  		})
    39  	})
    40  
    41  	Describe("command behavior", func() {
    42  		var (
    43  			orgName   string
    44  			spaceName string
    45  			quotaName string
    46  			username  string
    47  		)
    48  
    49  		BeforeEach(func() {
    50  			orgName = helpers.NewOrgName()
    51  			spaceName = helpers.NewSpaceName()
    52  			username, _ = helpers.GetCredentials()
    53  
    54  			helpers.SetupCF(orgName, spaceName)
    55  			quotaName = helpers.QuotaName()
    56  			totalMemory := "24M"
    57  			instanceMemory := "6M"
    58  			routes := "8"
    59  			serviceInstances := "2"
    60  			appInstances := "3"
    61  			reservedRoutePorts := "1"
    62  			session := helpers.CF("create-org-quota", quotaName, "-m", totalMemory, "-i", instanceMemory, "-r", routes, "-s", serviceInstances, "-a", appInstances, "--allow-paid-service-plans", "--reserved-route-ports", reservedRoutePorts)
    63  			Eventually(session).Should(Exit(0))
    64  		})
    65  
    66  		AfterEach(func() {
    67  			helpers.QuickDeleteOrg(orgName)
    68  		})
    69  
    70  		It("updates a quota", func() {
    71  			totalMemory := "25M"
    72  			instanceMemory := "5M"
    73  			serviceInstances := "1"
    74  			appInstances := "2"
    75  			reservedRoutePorts := "0"
    76  			session := helpers.CF("update-org-quota", quotaName, "-m", totalMemory, "-i", instanceMemory, "-s", serviceInstances, "-a", appInstances, "--disallow-paid-service-plans", "--reserved-route-ports", reservedRoutePorts)
    77  			Eventually(session).Should(Say(`Updating org quota %s as %s\.\.\.`, quotaName, username))
    78  			Eventually(session).Should(Exit(0))
    79  
    80  			session = helpers.CF("org-quota", quotaName)
    81  			Eventually(session).Should(Say(`total memory:\s+%s`, totalMemory))
    82  			Eventually(session).Should(Say(`instance memory:\s+%s`, instanceMemory))
    83  			Eventually(session).Should(Say(`routes:\s+%s`, "8"))
    84  			Eventually(session).Should(Say(`service instances:\s+%s`, serviceInstances))
    85  			Eventually(session).Should(Say(`paid service plans:\s+%s`, "disallowed"))
    86  			Eventually(session).Should(Say(`app instances:\s+%s`, appInstances))
    87  			Eventually(session).Should(Say(`route ports:\s+%s`, reservedRoutePorts))
    88  			Eventually(session).Should(Say(`log volume per second:\s+unlimited`))
    89  			Eventually(session).Should(Exit(0))
    90  		})
    91  
    92  		When("CAPI supports log rate limits", func() {
    93  			BeforeEach(func() {
    94  				helpers.SkipIfVersionLessThan(ccversion.MinVersionLogRateLimitingV3)
    95  			})
    96  
    97  			It("updates a quota", func() {
    98  				logVolume := "500B"
    99  				session := helpers.CF("update-org-quota", quotaName, "-l", logVolume)
   100  				Eventually(session).Should(Say(`Updating org quota %s as %s\.\.\.`, quotaName, username))
   101  				Eventually(session).Should(Exit(0))
   102  
   103  				session = helpers.CF("org-quota", quotaName)
   104  				Eventually(session).Should(Say(`log volume per second:\s+%s`, logVolume))
   105  				Eventually(session).Should(Exit(0))
   106  			})
   107  		})
   108  
   109  		When("the -n rename flag is provided", func() {
   110  			var newQuotaName string
   111  
   112  			BeforeEach(func() {
   113  				newQuotaName = helpers.QuotaName()
   114  			})
   115  
   116  			It("renames the quota", func() {
   117  				session := helpers.CF("update-org-quota", quotaName, "-n", newQuotaName)
   118  
   119  				Eventually(session).Should(Say(`Updating org quota %s as %s\.\.\.`, quotaName, username))
   120  				Eventually(session).Should(Exit(0))
   121  
   122  				session = helpers.CF("org-quota", newQuotaName)
   123  				Eventually(session).Should(Exit(0))
   124  			})
   125  
   126  			When("an org quota with the new name already exists", func() {
   127  				It("returns an unprocessable error from the API", func() {
   128  					session := helpers.CF("update-org-quota", quotaName, "-n", "default")
   129  
   130  					Eventually(session.Err).Should(Say(`Organization Quota 'default' already exists\.`))
   131  					Eventually(session).Should(Say("FAILED"))
   132  					Eventually(session).Should(Exit(1))
   133  				})
   134  			})
   135  		})
   136  
   137  		When("the named quota does not exist", func() {
   138  			It("displays a missing quota error message and fails", func() {
   139  				session := helpers.CF("update-org-quota", "bogus-org-quota")
   140  				Eventually(session).Should(Say(`Updating org quota bogus-org-quota as %s\.\.\.`, username))
   141  				Eventually(session).Should(Say("FAILED"))
   142  				Eventually(session.Err).Should(Say("Organization quota with name '%s' not found.", "bogus-org-quota"))
   143  				Eventually(session).Should(Exit(1))
   144  			})
   145  		})
   146  
   147  		When("no user-provided updates to the quota are specified", func() {
   148  			It("behaves idempotently and succeeds", func() {
   149  				session := helpers.CF("update-org-quota", quotaName)
   150  				Eventually(session).Should(Say(`Updating org quota %s as %s\.\.\.`, quotaName, username))
   151  				Eventually(session).Should(Say("OK"))
   152  				Eventually(session).Should(Exit(0))
   153  			})
   154  		})
   155  
   156  		When("conflicting flags are specified", func() {
   157  			It("displays a flag conflict error message and fails", func() {
   158  				session := helpers.CF("update-org-quota", quotaName, "--allow-paid-service-plans", "--disallow-paid-service-plans")
   159  				Eventually(session).Should(Say("FAILED"))
   160  				Eventually(session.Err).Should(Say(`Incorrect Usage: The following arguments cannot be used together: --allow-paid-service-plans, --disallow-paid-service-plans`))
   161  				Eventually(session).Should(Exit(1))
   162  			})
   163  		})
   164  	})
   165  })