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