github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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, 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 spacesSorted := []string{spaceName, spaceName2} 107 sort.Strings(spacesSorted) 108 Eventually(session).Should(Say(`spaces:\s+%s,.* %s`, spacesSorted[0], spacesSorted[1])) 109 110 Eventually(session).Should(Exit(0)) 111 }) 112 113 When("isolation segments are available", func() { 114 var isolationSegmentsSorted []string 115 116 BeforeEach(func() { 117 isolationSegmentName1 := helpers.NewIsolationSegmentName() 118 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName1)).Should(Exit(0)) 119 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName1)).Should(Exit(0)) 120 121 isolationSegmentName2 := helpers.NewIsolationSegmentName() 122 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName2)).Should(Exit(0)) 123 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName2)).Should(Exit(0)) 124 125 isolationSegmentsSorted = []string{isolationSegmentName1, isolationSegmentName2} 126 sort.Strings(isolationSegmentsSorted) 127 128 Eventually(helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentsSorted[0])).Should(Exit(0)) 129 }) 130 131 It("displays isolation segment information in the org table", func() { 132 session := helpers.CF("org", orgName) 133 134 Eventually(session).Should(Say(`isolation segments:\s+.*%s \(default\),.* %s`, isolationSegmentsSorted[0], isolationSegmentsSorted[1])) 135 }) 136 }) 137 }) 138 }) 139 }) 140 })