github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/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 Context("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 Context("when the environment is not setup correctly", func() { 42 Context("when no API endpoint is set", func() { 43 BeforeEach(func() { 44 helpers.UnsetAPI() 45 }) 46 47 It("fails with no API endpoint set message", func() { 48 session := helpers.CF("org", orgName) 49 Eventually(session.Out).Should(Say("FAILED")) 50 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 51 Eventually(session).Should(Exit(1)) 52 }) 53 }) 54 55 Context("when not logged in", func() { 56 BeforeEach(func() { 57 helpers.LogoutCF() 58 }) 59 60 It("fails with not logged in message", func() { 61 session := helpers.CF("org", orgName) 62 Eventually(session.Out).Should(Say("FAILED")) 63 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 64 Eventually(session).Should(Exit(1)) 65 }) 66 }) 67 }) 68 69 Context("when the environment is set up correctly", func() { 70 BeforeEach(func() { 71 helpers.LoginCF() 72 }) 73 74 Context("when the org does not exist", func() { 75 It("displays org not found and exits 1", func() { 76 session := helpers.CF("org", orgName) 77 userName, _ := helpers.GetCredentials() 78 Eventually(session.Out).Should(Say("Getting info for org %s as %s\\.\\.\\.", orgName, userName)) 79 Eventually(session.Out).Should(Say("FAILED")) 80 Eventually(session.Err).Should(Say("Organization '%s' not found.", orgName)) 81 Eventually(session).Should(Exit(1)) 82 }) 83 }) 84 85 Context("when the org exists", func() { 86 BeforeEach(func() { 87 setupCF(orgName, spaceName) 88 }) 89 90 AfterEach(func() { 91 helpers.QuickDeleteOrg(orgName) 92 }) 93 94 Context("when the --guid flag is used", func() { 95 It("displays the org guid", func() { 96 session := helpers.CF("org", "--guid", orgName) 97 Eventually(session.Out).Should(Say("[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}")) 98 Eventually(session).Should(Exit(0)) 99 }) 100 }) 101 102 Context("when no flags are used", func() { 103 var ( 104 domainName string 105 quotaName string 106 spaceName2 string 107 isolationSegmentsSorted []string 108 ) 109 110 BeforeEach(func() { 111 domainName = helpers.DomainName("") 112 domain := helpers.NewDomain(orgName, domainName) 113 domain.Create() 114 115 quotaName = helpers.QuotaName() 116 session := helpers.CF("create-quota", quotaName) 117 Eventually(session).Should(Exit(0)) 118 session = helpers.CF("set-quota", orgName, quotaName) 119 Eventually(session).Should(Exit(0)) 120 121 spaceName2 = helpers.NewSpaceName() 122 helpers.CreateSpace(spaceName2) 123 124 isolationSegmentName1 := helpers.NewIsolationSegmentName() 125 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName1)).Should(Exit(0)) 126 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName1)).Should(Exit(0)) 127 128 isolationSegmentName2 := helpers.NewIsolationSegmentName() 129 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName2)).Should(Exit(0)) 130 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName2)).Should(Exit(0)) 131 132 isolationSegmentsSorted = []string{isolationSegmentName1, isolationSegmentName2} 133 sort.Strings(isolationSegmentsSorted) 134 135 Eventually(helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentsSorted[0])).Should(Exit(0)) 136 }) 137 138 It("displays a table with org domains, quotas, spaces, space quotas and isolation segments, and exits 0", func() { 139 session := helpers.CF("org", orgName) 140 userName, _ := helpers.GetCredentials() 141 Eventually(session.Out).Should(Say("Getting info for org %s as %s\\.\\.\\.", orgName, userName)) 142 143 Eventually(session.Out).Should(Say("name:\\s+%s", orgName)) 144 145 domainsSorted := []string{defaultSharedDomain(), domainName} 146 sort.Strings(domainsSorted) 147 Eventually(session.Out).Should(Say("domains:.+%s,.+%s", domainsSorted[0], domainsSorted[1])) 148 149 Eventually(session.Out).Should(Say("quota:\\s+%s", quotaName)) 150 151 spacesSorted := []string{spaceName, spaceName2} 152 sort.Strings(spacesSorted) 153 Eventually(session.Out).Should(Say("spaces:\\s+%s,.* %s", spacesSorted[0], spacesSorted[1])) 154 155 Eventually(session.Out).Should(Say("isolation segments:\\s+.*%s \\(default\\),.* %s", isolationSegmentsSorted[0], isolationSegmentsSorted[1])) 156 157 Eventually(session).Should(Exit(0)) 158 }) 159 }) 160 }) 161 }) 162 })