github.com/loafoe/cli@v7.1.0+incompatible/integration/v7/isolated/set_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("set-org-quota command", func() { 13 var ( 14 orgName string 15 quotaName string 16 ) 17 BeforeEach(func() { 18 orgName = helpers.NewOrgName() 19 20 helpers.SetupCFWithOrgOnly(orgName) 21 quotaName = helpers.QuotaName() 22 session := helpers.CF("create-org-quota", quotaName) 23 Eventually(session).Should(Exit(0)) 24 }) 25 26 When("the environment is not setup correctly", func() { 27 It("fails with the appropriate errors", func() { 28 helpers.CheckEnvironmentTargetedCorrectly(false, false, "test-org", "set-org-quota", orgName, quotaName) 29 }) 30 }) 31 32 When("the environment is setup correctly", func() { 33 AfterEach(func() { 34 helpers.QuickDeleteOrg(orgName) 35 }) 36 37 Describe("help", func() { 38 When("--help flag is set", func() { 39 It("appears in cf help -a", func() { 40 session := helpers.CF("help", "-a") 41 Eventually(session).Should(Exit(0)) 42 Expect(session).To(HaveCommandInCategoryWithDescription("set-org-quota", "ORG ADMIN", "Assign a quota to an organization")) 43 }) 44 45 It("Displays command usage to output", func() { 46 session := helpers.CF("set-org-quota", "--help") 47 Eventually(session).Should(Say("NAME:")) 48 Eventually(session).Should(Say("set-org-quota - Assign a quota to an organization")) 49 Eventually(session).Should(Say("USAGE:")) 50 Eventually(session).Should(Say("cf set-org-quota ORG QUOTA")) 51 Eventually(session).Should(Say("ALIAS:")) 52 Eventually(session).Should(Say("set-quota")) 53 Eventually(session).Should(Say("SEE ALSO:")) 54 Eventually(session).Should(Say("org-quotas, orgs")) 55 Eventually(session).Should(Exit(0)) 56 }) 57 }) 58 }) 59 60 When("valid arguments are provided", func() { 61 It("sets the quota on an org", func() { 62 session := helpers.CF("set-org-quota", orgName, quotaName) 63 Eventually(session).Should(Say("Setting quota %s to org %s", quotaName, orgName)) 64 Eventually(session).Should(Say("OK")) 65 Eventually(session).Should(Exit(0)) 66 67 session = helpers.CF("org", orgName) 68 Eventually(session).Should(Say(`(?i)quota:\s+%s`, quotaName)) 69 Eventually(session).Should(Exit(0)) 70 }) 71 72 When("the quota is already applied to the org", func() { 73 BeforeEach(func() { 74 session := helpers.CF("set-org-quota", orgName, quotaName) 75 Eventually(session).Should(Exit(0)) 76 }) 77 78 It("sets the quota on a org", func() { 79 session := helpers.CF("set-org-quota", orgName, quotaName) 80 Eventually(session).Should(Say("Setting quota %s to org %s", quotaName, orgName)) 81 Eventually(session).Should(Say("OK")) 82 Eventually(session).Should(Exit(0)) 83 }) 84 }) 85 }) 86 87 When("invalid arguments are provided", func() { 88 It("fails and informs the user an invalid quota was provided", func() { 89 session := helpers.CF("set-org-quota", orgName, "fake-name") 90 Eventually(session).Should(Say("FAILED")) 91 Eventually(session.Err).Should(Say("Organization quota with name '%s' not found.", "fake-name")) 92 Eventually(session).Should(Exit(1)) 93 }) 94 95 It("fails and informs the user an invalid org was provided", func() { 96 session := helpers.CF("set-org-quota", "fake-name", quotaName) 97 Eventually(session).Should(Say("FAILED")) 98 Eventually(session.Err).Should(Say("Organization 'fake-name' not found.")) 99 Eventually(session).Should(Exit(1)) 100 }) 101 }) 102 103 When("the incorrect number of positional arguments are provided", func() { 104 It("fails and informs the user a positional argument is missing", func() { 105 session := helpers.CF("set-org-quota", orgName) 106 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `QUOTA` was not provided")) 107 Eventually(session).Should(Say("NAME:")) 108 Eventually(session).Should(Exit(1)) 109 }) 110 111 It("fails and reminds the user only two positional args are needed", func() { 112 session := helpers.CF("set-org-quota", orgName, quotaName, "extra") 113 Eventually(session.Err).Should(Say(`Incorrect Usage: unexpected argument "extra"`)) 114 Eventually(session).Should(Say("NAME:")) 115 Eventually(session).Should(Exit(1)) 116 }) 117 }) 118 }) 119 })