github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+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 Context("when the --guid flag is used", func() { 91 It("displays the org guid", func() { 92 session := helpers.CF("org", "--guid", orgName) 93 Eventually(session.Out).Should(Say("[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}")) 94 Eventually(session).Should(Exit(0)) 95 }) 96 }) 97 98 Context("when no flags are used", func() { 99 var ( 100 domainName string 101 quotaName string 102 spaceName2 string 103 isolationSegmentName1 string 104 isolationSegmentName2 string 105 ) 106 107 BeforeEach(func() { 108 domainName = helpers.DomainName("") 109 domain := helpers.NewDomain(orgName, domainName) 110 domain.Create() 111 112 quotaName = helpers.QuotaName() 113 session := helpers.CF("create-quota", quotaName) 114 Eventually(session).Should(Exit(0)) 115 session = helpers.CF("set-quota", orgName, quotaName) 116 Eventually(session).Should(Exit(0)) 117 118 spaceName2 = helpers.NewSpaceName() 119 helpers.CreateSpace(spaceName2) 120 121 isolationSegmentName1 = helpers.IsolationSegmentName() 122 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName1)).Should(Exit(0)) 123 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName1)).Should(Exit(0)) 124 125 isolationSegmentName2 = helpers.IsolationSegmentName() 126 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName2)).Should(Exit(0)) 127 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName2)).Should(Exit(0)) 128 }) 129 130 // @TODO remove and add to cleanup script 131 AfterEach(func() { 132 Eventually(helpers.CF("delete-org", "-f", orgName)) 133 Eventually(helpers.CF("delete-isolation-segment", "-f", isolationSegmentName1)) 134 Eventually(helpers.CF("delete-isolation-segment", "-f", isolationSegmentName2)) 135 }) 136 137 It("displays a table with org domains, quotas, spaces, space quotas and isolation segments, and exits 0", func() { 138 session := helpers.CF("org", orgName) 139 userName, _ := helpers.GetCredentials() 140 Eventually(session.Out).Should(Say("Getting info for org %s as %s...", orgName, userName)) 141 142 Eventually(session.Out).Should(Say("name:\\s+%s", orgName)) 143 144 domainsSorted := []string{defaultSharedDomain(), domainName} 145 sort.Strings(domainsSorted) 146 Eventually(session.Out).Should(Say("domains:.+%s,.+%s", domainsSorted[0], domainsSorted[1])) 147 148 Eventually(session.Out).Should(Say("quota:\\s+%s", quotaName)) 149 150 spacesSorted := []string{spaceName, spaceName2} 151 sort.Strings(spacesSorted) 152 Eventually(session.Out).Should(Say("spaces:\\s+%s,.* %s", spacesSorted[0], spacesSorted[1])) 153 154 isolationSegmentsSorted := []string{isolationSegmentName1, isolationSegmentName2} 155 sort.Strings(isolationSegmentsSorted) 156 Eventually(session.Out).Should(Say("isolation segments:\\s+.*%s,.* %s", isolationSegmentsSorted[0], isolationSegmentsSorted[1])) 157 158 Eventually(session).Should(Exit(0)) 159 }) 160 }) 161 }) 162 }) 163 })