github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/org_command_test.go (about) 1 package isolated 2 3 import ( 4 "sort" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("org command", func() { 14 var ( 15 orgName string 16 spaceName string 17 ) 18 19 BeforeEach(func() { 20 orgName = helpers.NewOrgName() 21 spaceName = helpers.NewSpaceName() 22 }) 23 24 Describe("help", func() { 25 When("--help flag is set", func() { 26 It("Displays command usage to output", func() { 27 session := helpers.CF("org", "--help") 28 Eventually(session).Should(Say("NAME:")) 29 Eventually(session).Should(Say("org - Show org info")) 30 Eventually(session).Should(Say("USAGE:")) 31 Eventually(session).Should(Say("cf org ORG [--guid]")) 32 Eventually(session).Should(Say("OPTIONS:")) 33 Eventually(session).Should(Say(`--guid\s+Retrieve and display the given org's guid. All other output for the org is suppressed.`)) 34 Eventually(session).Should(Say("SEE ALSO:")) 35 Eventually(session).Should(Say("org-users, orgs")) 36 Eventually(session).Should(Exit(0)) 37 }) 38 }) 39 }) 40 41 When("the environment is not setup correctly", func() { 42 It("fails with the appropriate errors", func() { 43 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "org", "org-name") 44 }) 45 }) 46 47 When("the environment is set up correctly", func() { 48 BeforeEach(func() { 49 helpers.LoginCF() 50 }) 51 52 When("the org does not exist", func() { 53 It("displays org not found and exits 1", func() { 54 session := helpers.CF("org", orgName) 55 userName, _ := helpers.GetCredentials() 56 Eventually(session).Should(Say(`Getting info for org %s as %s\.\.\.`, orgName, userName)) 57 Eventually(session).Should(Say("FAILED")) 58 Eventually(session.Err).Should(Say("Organization '%s' not found.", orgName)) 59 Eventually(session).Should(Exit(1)) 60 }) 61 }) 62 63 When("the org exists", func() { 64 BeforeEach(func() { 65 helpers.SetupCF(orgName, spaceName) 66 }) 67 68 AfterEach(func() { 69 helpers.QuickDeleteOrg(orgName) 70 }) 71 72 When("the --guid flag is used", func() { 73 It("displays the org guid", func() { 74 session := helpers.CF("org", "--guid", orgName) 75 Eventually(session).Should(Say(`[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}`)) 76 Eventually(session).Should(Exit(0)) 77 }) 78 }) 79 80 When("no flags are used", func() { 81 var ( 82 domainName string 83 spaceName2 string 84 ) 85 86 BeforeEach(func() { 87 domainName = helpers.NewDomainName("") 88 domain := helpers.NewDomain(orgName, domainName) 89 domain.Create() 90 91 spaceName2 = helpers.NewSpaceName() 92 helpers.CreateSpace(spaceName2) 93 }) 94 95 It("displays a table with org domains, applied quota, spaces, space and isolation segments, and exits 0", func() { 96 session := helpers.CF("org", orgName) 97 userName, _ := helpers.GetCredentials() 98 Eventually(session).Should(Say(`Getting info for org %s as %s\.\.\.`, orgName, userName)) 99 100 Eventually(session).Should(Say(`name:\s+%s`, orgName)) 101 102 domainsSorted := []string{helpers.DefaultSharedDomain(), domainName} 103 sort.Strings(domainsSorted) 104 Eventually(session).Should(Say("domains:.+%s,.+%s", domainsSorted[0], domainsSorted[1])) 105 106 Eventually(session).Should(Say(`quota:\s+default`)) 107 108 spacesSorted := []string{spaceName, spaceName2} 109 sort.Strings(spacesSorted) 110 Eventually(session).Should(Say(`spaces:\s+%s,.* %s`, spacesSorted[0], spacesSorted[1])) 111 112 Eventually(session).Should(Exit(0)) 113 }) 114 115 When("isolation segments are available", func() { 116 var isolationSegmentsSorted []string 117 118 BeforeEach(func() { 119 isolationSegmentName1 := helpers.NewIsolationSegmentName() 120 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName1)).Should(Exit(0)) 121 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName1)).Should(Exit(0)) 122 123 isolationSegmentName2 := helpers.NewIsolationSegmentName() 124 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName2)).Should(Exit(0)) 125 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName2)).Should(Exit(0)) 126 127 isolationSegmentsSorted = []string{isolationSegmentName1, isolationSegmentName2} 128 sort.Strings(isolationSegmentsSorted) 129 130 Eventually(helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentsSorted[0])).Should(Exit(0)) 131 }) 132 133 It("displays isolation segment information in the org table", func() { 134 session := helpers.CF("org", orgName) 135 136 Eventually(session).Should(Say(`isolation segments:\s+.*%s \(default\),.* %s`, isolationSegmentsSorted[0], isolationSegmentsSorted[1])) 137 }) 138 }) 139 140 When("a custom quota is applied", func() { 141 var quotaName string 142 143 BeforeEach(func() { 144 quotaName = helpers.NewOrgQuotaName() 145 Eventually(helpers.CF("create-org-quota", quotaName)).Should(Exit(0)) 146 147 // TODO use set-org-quota here when it's done in V7 148 Eventually(helpers.CF("set-quota", orgName, quotaName)).Should(Exit(0)) 149 }) 150 151 It("displays isolation segment information in the org table", func() { 152 session := helpers.CF("org", orgName) 153 154 Eventually(session).Should(Say(`quota:\s+%s`, quotaName)) 155 }) 156 }) 157 }) 158 }) 159 }) 160 })