github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/isolated/isolation_segments_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 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 . "github.com/onsi/gomega/ghttp" 11 ) 12 13 var _ = Describe("isolation-segments command", func() { 14 BeforeEach(func() { 15 helpers.SkipIfVersionLessThan(ccversion.MinVersionIsolationSegmentV3) 16 }) 17 18 Describe("help", func() { 19 When("--help flag is set", func() { 20 It("Displays command usage to output", func() { 21 session := helpers.CF("isolation-segments", "--help") 22 Eventually(session).Should(Say("NAME:")) 23 Eventually(session).Should(Say("isolation-segments - List all isolation segments")) 24 Eventually(session).Should(Say("USAGE:")) 25 Eventually(session).Should(Say("cf isolation-segments")) 26 Eventually(session).Should(Say("SEE ALSO:")) 27 Eventually(session).Should(Say("create-isolation-segment, enable-org-isolation")) 28 Eventually(session).Should(Exit(0)) 29 }) 30 }) 31 }) 32 33 When("the environment is not setup correctly", func() { 34 It("fails with the appropriate errors", func() { 35 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "isolation-segments") 36 }) 37 38 When("the v3 api version is lower than the minimum version", func() { 39 var server *Server 40 41 BeforeEach(func() { 42 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion) 43 }) 44 45 AfterEach(func() { 46 server.Close() 47 }) 48 49 It("fails with error message that the minimum version is not met", func() { 50 session := helpers.CF("isolation-segments") 51 Eventually(session).Should(Say("FAILED")) 52 Eventually(session.Err).Should(Say(`This command requires CF API version 3\.11\.0 or higher\.`)) 53 Eventually(session).Should(Exit(1)) 54 }) 55 }) 56 }) 57 58 When("the environment is set up correctly", func() { 59 BeforeEach(func() { 60 helpers.LoginCF() 61 }) 62 63 When("there are some isolation segments", func() { 64 var isolationSegment1 string // No orgs assigned 65 var isolationSegment2 string // One org assigned 66 var isolationSegment3 string // Many orgs assigned 67 var org1 string 68 var org2 string 69 70 BeforeEach(func() { 71 org1 = helpers.NewOrgName() 72 org2 = helpers.NewOrgName() 73 helpers.CreateOrg(org1) 74 helpers.CreateOrg(org2) 75 76 isolationSegment1 = helpers.NewIsolationSegmentName() 77 isolationSegment2 = helpers.NewIsolationSegmentName() 78 isolationSegment3 = helpers.NewIsolationSegmentName() 79 80 Eventually(helpers.CF("create-isolation-segment", isolationSegment1)).Should(Exit(0)) 81 Eventually(helpers.CF("create-isolation-segment", isolationSegment2)).Should(Exit(0)) 82 Eventually(helpers.CF("create-isolation-segment", isolationSegment3)).Should(Exit(0)) 83 Eventually(helpers.CF("enable-org-isolation", org1, isolationSegment2)).Should(Exit(0)) 84 Eventually(helpers.CF("enable-org-isolation", org1, isolationSegment3)).Should(Exit(0)) 85 Eventually(helpers.CF("enable-org-isolation", org2, isolationSegment3)).Should(Exit(0)) 86 }) 87 88 AfterEach(func() { 89 helpers.QuickDeleteOrg(org1) 90 helpers.QuickDeleteOrg(org2) 91 }) 92 93 It("returns an ok and displays the table", func() { 94 userName, _ := helpers.GetCredentials() 95 session := helpers.CF("isolation-segments") 96 Eventually(session).Should(Say("Getting isolation segments as %s...", userName)) 97 Eventually(session).Should(Say("OK")) 98 Eventually(session).Should(Say(`name\s+orgs`)) 99 Eventually(session).Should(Say("shared")) 100 Eventually(session).Should(Say(`%s\s+`, isolationSegment1)) 101 Eventually(session).Should(Say(`%s\s+%s`, isolationSegment2, org1)) 102 Eventually(session).Should(Say(`%s\s+%s, %s`, isolationSegment3, org1, org2)) 103 Eventually(session).Should(Exit(0)) 104 }) 105 }) 106 }) 107 })