github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/update_space_quota_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 _ = Describe("update-space-quota command", func() {
    12  	var (
    13  		quotaName string
    14  	)
    15  
    16  	BeforeEach(func() {
    17  		quotaName = helpers.QuotaName()
    18  	})
    19  
    20  	Describe("help", func() {
    21  		When("--help flag is set", func() {
    22  			It("Displays command usage to output", func() {
    23  				session := helpers.CF("update-space-quota", "--help")
    24  				Eventually(session).Should(Say("NAME:"))
    25  				Eventually(session).Should(Say("update-space-quota - Update an existing space quota"))
    26  				Eventually(session).Should(Say("USAGE:"))
    27  				Eventually(session).Should(Say(`cf update-space-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\] \[--allow-paid-service-plans\] \[--reserved-route-ports RESERVED_ROUTE_PORTS\]`))
    28  				Eventually(session).Should(Say("OPTIONS:"))
    29  				Eventually(session).Should(Say(`-a\s+Total number of application instances. -1 represents an unlimited amount.`))
    30  				Eventually(session).Should(Say(`--allow-paid-service-plans\s+Allow provisioning instances of paid service plans.`))
    31  				Eventually(session).Should(Say(`--disallow-paid-service-plans\s+Disallow provisioning instances of paid service plans.`))
    32  				Eventually(session).Should(Say(`-i\s+Maximum amount of memory a process can have \(e.g. 1024M, 1G, 10G\). -1 represents an unlimited amount.`))
    33  				Eventually(session).Should(Say(`-m\s+Total amount of memory all processes can have \(e.g. 1024M, 1G, 10G\).  -1 represents an unlimited amount.`))
    34  				Eventually(session).Should(Say(`-n\s+New name`))
    35  				Eventually(session).Should(Say(`-r\s+Total number of routes. -1 represents an unlimited amount.`))
    36  				Eventually(session).Should(Say(`--reserved-route-ports\s+Maximum number of routes that may be created with ports. -1 represents an unlimited amount.`))
    37  				Eventually(session).Should(Say(`-s\s+Total number of service instances. -1 represents an unlimited amount.`))
    38  				Eventually(session).Should(Say("SEE ALSO:"))
    39  				Eventually(session).Should(Say("space, space-quota, space-quotas"))
    40  				Eventually(session).Should(Exit(0))
    41  			})
    42  		})
    43  	})
    44  
    45  	When("the environment is not setup correctly", func() {
    46  		It("fails with the appropriate errors", func() {
    47  			helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "space-quota", quotaName)
    48  		})
    49  	})
    50  
    51  	When("the environment is set up correctly", func() {
    52  		var (
    53  			orgName   string
    54  			spaceName string
    55  			userName  string
    56  		)
    57  
    58  		BeforeEach(func() {
    59  			orgName = helpers.NewOrgName()
    60  			spaceName = helpers.NewSpaceName()
    61  			helpers.SetupCF(orgName, spaceName)
    62  			userName, _ = helpers.GetCredentials()
    63  
    64  			totalMemory := "24M"
    65  			instanceMemory := "6M"
    66  			routes := "8"
    67  			serviceInstances := "2"
    68  			appInstances := "3"
    69  			reservedRoutePorts := "1"
    70  			session := helpers.CF("create-space-quota", quotaName, "-m", totalMemory, "-i", instanceMemory, "-r", routes, "-s", serviceInstances, "-a", appInstances, "--allow-paid-service-plans", "--reserved-route-ports", reservedRoutePorts)
    71  			Eventually(session).Should(Exit(0))
    72  		})
    73  
    74  		AfterEach(func() {
    75  			helpers.QuickDeleteOrg(orgName)
    76  		})
    77  
    78  		It("updates a space quota", func() {
    79  			totalMemory := "25M"
    80  			instanceMemory := "5M"
    81  			serviceInstances := "1"
    82  			appInstances := "2"
    83  			reservedRoutePorts := "0"
    84  			session := helpers.CF("update-space-quota", quotaName, "-m", totalMemory, "-i", instanceMemory, "-s", serviceInstances, "-a", appInstances, "--allow-paid-service-plans", "--reserved-route-ports", reservedRoutePorts)
    85  			Eventually(session).Should(Say("Updating space quota %s for org %s as %s...", quotaName, orgName, userName))
    86  			Eventually(session).Should(Say("OK"))
    87  			Eventually(session).Should(Exit(0))
    88  
    89  			session = helpers.CF("space-quota", quotaName)
    90  			Eventually(session).Should(Say(`total memory:\s+%s`, totalMemory))
    91  			Eventually(session).Should(Say(`instance memory:\s+%s`, instanceMemory))
    92  			Eventually(session).Should(Say(`routes:\s+%s`, "8"))
    93  			Eventually(session).Should(Say(`service instances:\s+%s`, serviceInstances))
    94  			Eventually(session).Should(Say(`paid service plans:\s+%s`, "allowed"))
    95  			Eventually(session).Should(Say(`app instances:\s+%s`, appInstances))
    96  			Eventually(session).Should(Say(`route ports:\s+%s`, reservedRoutePorts))
    97  			Eventually(session).Should(Exit(0))
    98  		})
    99  
   100  		When("the named quota does not exist", func() {
   101  			It("displays a missing quota error message and fails", func() {
   102  				session := helpers.CF("update-space-quota", "bogota")
   103  				Eventually(session).Should(Say(`Updating space quota bogota for org %s as %s\.\.\.`, orgName, userName))
   104  				Eventually(session).Should(Say("FAILED"))
   105  				Eventually(session.Err).Should(Say("Space quota with name '%s' not found.", "bogota"))
   106  				Eventually(session).Should(Exit(1))
   107  			})
   108  		})
   109  
   110  		When("conflicting flags are specified", func() {
   111  			It("displays a flag conflict error message and fails", func() {
   112  				session := helpers.CF("update-space-quota", quotaName, "--allow-paid-service-plans", "--disallow-paid-service-plans")
   113  				Eventually(session).Should(Say("FAILED"))
   114  				Eventually(session.Err).Should(Say(`Incorrect Usage: The following arguments cannot be used together: --allow-paid-service-plans, --disallow-paid-service-plans`))
   115  				Eventually(session).Should(Exit(1))
   116  			})
   117  		})
   118  	})
   119  })