github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/create_org_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 command", func() { 13 var ( 14 orgNameNew string 15 ) 16 17 BeforeEach(func() { 18 orgNameNew = helpers.NewOrgName() 19 }) 20 21 Describe("help", func() { 22 When("--help flag is set", func() { 23 It("appears in cf help -a", func() { 24 session := helpers.CF("help", "-a") 25 Eventually(session).Should(Exit(0)) 26 Expect(session).To(HaveCommandInCategoryWithDescription("create-org", "ORGS", "Create an org")) 27 }) 28 29 It("Displays command usage to output", func() { 30 session := helpers.CF("create-org", "--help") 31 Eventually(session).Should(Say("NAME:")) 32 Eventually(session).Should(Say("create-org - Create an org")) 33 Eventually(session).Should(Say("USAGE:")) 34 Eventually(session).Should(Say(`cf create-org ORG \[-q ORG_QUOTA\]`)) 35 Eventually(session).Should(Say("ALIAS:")) 36 Eventually(session).Should(Say(`co`)) 37 Eventually(session).Should(Say("OPTIONS:")) 38 Eventually(session).Should(Say(`--quota, -q\s+Quota to assign to the newly created org`)) 39 Eventually(session).Should(Say("SEE ALSO:")) 40 Eventually(session).Should(Say("create-space, org-quotas, orgs, set-org-role")) 41 Eventually(session).Should(Exit(0)) 42 }) 43 }) 44 45 When("the org name is not provided", func() { 46 It("tells the user that the org name is required, prints help text, and exits 1", func() { 47 session := helpers.CF("create-org") 48 49 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ORG` was not provided")) 50 Eventually(session).Should(Say("NAME:")) 51 Eventually(session).Should(Exit(1)) 52 }) 53 }) 54 }) 55 56 When("the environment is not setup correctly", func() { 57 It("fails with the appropriate errors", func() { 58 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "create-org", orgNameNew) 59 }) 60 }) 61 62 When("the environment is set up correctly", func() { 63 BeforeEach(func() { 64 helpers.LoginCF() 65 }) 66 67 AfterEach(func() { 68 helpers.QuickDeleteOrg(orgNameNew) 69 }) 70 71 When("the org does not exist", func() { 72 It("creates the org", func() { 73 session := helpers.CF("create-org", orgNameNew) 74 userName, _ := helpers.GetCredentials() 75 Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName)) 76 Eventually(session).Should(Say("OK")) 77 78 Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s"' to target new org`, orgNameNew)) 79 Eventually(session).Should(Exit(0)) 80 81 session = helpers.CF("org", orgNameNew) 82 Eventually(session).Should(Say(`name:\s+%s`, orgNameNew)) 83 Eventually(session).Should(Exit(0)) 84 }) 85 }) 86 87 When("the org already exists", func() { 88 BeforeEach(func() { 89 Eventually(helpers.CF("create-org", orgNameNew)).Should(Exit(0)) 90 }) 91 92 It("fails to create the org", func() { 93 session := helpers.CF("create-org", orgNameNew) 94 userName, _ := helpers.GetCredentials() 95 Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName)) 96 Eventually(session).Should(Say(`Organization '%s' already exists\.`, orgNameNew)) 97 Eventually(session).Should(Say("OK")) 98 Eventually(session).Should(Exit(0)) 99 }) 100 }) 101 102 When("the -quota flag is passed", func() { 103 When("the quota does not exist", func() { 104 var ( 105 quotaName = "garb-quota" 106 ) 107 108 It("makes an org with the default quota and informs the user setting the quota has failed", func() { 109 session := helpers.CF("create-org", orgNameNew, "-q", quotaName) 110 userName, _ := helpers.GetCredentials() 111 Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName)) 112 Eventually(session).Should(Say("OK")) 113 114 Eventually(session).Should(Say("Setting org quota %s to org %s as %s...", quotaName, orgNameNew, userName)) 115 Eventually(session.Err).Should(Say("Organization quota with name '%s' not found.", quotaName)) 116 Eventually(session).Should(Say("FAILED")) 117 118 session = helpers.CF("org", orgNameNew) 119 Eventually(session).Should(Say(`name:\s+%s`, orgNameNew)) 120 Eventually(session).Should(Say(`quota:\s+%s`, `default`)) 121 Eventually(session).Should(Exit(0)) 122 }) 123 }) 124 125 When("the quota exists", func() { 126 var ( 127 quotaName = helpers.QuotaName() 128 ) 129 130 BeforeEach(func() { 131 Eventually(helpers.CF("create-org-quota", quotaName)).Should(Exit(0)) 132 }) 133 134 It("makes an org with the given quota", func() { 135 session := helpers.CF("create-org", orgNameNew, "-q", quotaName) 136 userName, _ := helpers.GetCredentials() 137 Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName)) 138 Eventually(session).Should(Say("OK")) 139 140 Eventually(session).Should(Say("Setting org quota %s to org %s as %s...", quotaName, orgNameNew, userName)) 141 Eventually(session).Should(Say("OK")) 142 143 Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s"' to target new org`, orgNameNew)) 144 Eventually(session).Should(Exit(0)) 145 146 session = helpers.CF("org", orgNameNew) 147 Eventually(session).Should(Say(`name:\s+%s`, orgNameNew)) 148 Eventually(session).Should(Say(`quota:\s+%s`, quotaName)) 149 Eventually(session).Should(Exit(0)) 150 }) 151 }) 152 }) 153 }) 154 })