github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/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 orgName string 15 orgNameNew string 16 spaceName string 17 ) 18 19 BeforeEach(func() { 20 orgName = helpers.NewOrgName() 21 orgNameNew = helpers.NewOrgName() 22 spaceName = helpers.NewSpaceName() 23 }) 24 25 Describe("help", func() { 26 When("--help flag is set", func() { 27 It("appears in cf help -a", func() { 28 session := helpers.CF("help", "-a") 29 Eventually(session).Should(Exit(0)) 30 Expect(session).To(HaveCommandInCategoryWithDescription("create-org", "ORGS", "Create an org")) 31 }) 32 33 It("Displays command usage to output", func() { 34 session := helpers.CF("create-org", "--help") 35 Eventually(session).Should(Say("NAME:")) 36 Eventually(session).Should(Say("create-org - Create an org")) 37 Eventually(session).Should(Say("USAGE:")) 38 Eventually(session).Should(Say(`cf create-org ORG`)) 39 Eventually(session).Should(Say("ALIAS:")) 40 Eventually(session).Should(Say(`co`)) 41 Eventually(session).Should(Say("SEE ALSO:")) 42 Eventually(session).Should(Say("create-space, orgs, quotas, set-org-role")) 43 Eventually(session).Should(Exit(0)) 44 }) 45 }) 46 }) 47 48 When("the org name is not provided", func() { 49 It("tells the user that the org name is required, prints help text, and exits 1", func() { 50 session := helpers.CF("create-org") 51 52 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ORG` was not provided")) 53 Eventually(session).Should(Say("NAME:")) 54 Eventually(session).Should(Exit(1)) 55 }) 56 }) 57 58 When("the environment is not setup correctly", func() { 59 It("fails with the appropriate errors", func() { 60 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "create-org", orgNameNew) 61 }) 62 }) 63 64 When("the environment is set up correctly", func() { 65 BeforeEach(func() { 66 helpers.SetupCF(orgName, spaceName) 67 }) 68 69 AfterEach(func() { 70 helpers.QuickDeleteOrg(orgName) 71 }) 72 73 When("the org does not exist", func() { 74 It("creates the org", func() { 75 session := helpers.CF("create-org", orgNameNew) 76 userName, _ := helpers.GetCredentials() 77 Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName)) 78 Eventually(session).Should(Say("OK")) 79 80 Eventually(session).Should(Say("Assigning role OrgManager to user %s in org %s as %s...", userName, orgNameNew, userName)) 81 Eventually(session).Should(Say("OK")) 82 83 Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s"' to target new org`, orgNameNew)) 84 Eventually(session).Should(Exit(0)) 85 86 session = helpers.CF("org", orgNameNew) 87 Eventually(session).Should(Say(`name:\s+%s`, orgNameNew)) 88 Eventually(session).Should(Exit(0)) 89 }) 90 }) 91 92 When("the org already exists", func() { 93 BeforeEach(func() { 94 Eventually(helpers.CF("create-org", orgNameNew)).Should(Exit(0)) 95 }) 96 97 It("fails to create the org", func() { 98 session := helpers.CF("create-org", orgNameNew) 99 userName, _ := helpers.GetCredentials() 100 Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName)) 101 Eventually(session).Should(Say(`Organization '%s' already exists\.`, orgNameNew)) 102 Eventually(session).Should(Say("OK")) 103 Eventually(session).Should(Exit(0)) 104 }) 105 }) 106 }) 107 })