github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/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 Context("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 Context("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 Context("when the v3 api does not exist", func() { 39 var server *Server 40 41 BeforeEach(func() { 42 server = helpers.StartAndTargetServerWithoutV3API() 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 Context("when the v3 api version is lower than the minimum version", func() { 58 var server *Server 59 60 BeforeEach(func() { 61 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0") 62 }) 63 64 AfterEach(func() { 65 server.Close() 66 }) 67 68 It("fails with error message that the minimum version is not met", func() { 69 session := helpers.CF("isolation-segments") 70 Eventually(session).Should(Say("FAILED")) 71 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 72 Eventually(session).Should(Exit(1)) 73 }) 74 }) 75 }) 76 77 Context("when the environment is set up correctly", func() { 78 BeforeEach(func() { 79 helpers.LoginCF() 80 }) 81 82 Context("when there are some isolation segments", func() { 83 var isolationSegment1 string // No orgs assigned 84 var isolationSegment2 string // One org assigned 85 var isolationSegment3 string // Many orgs assigned 86 var org1 string 87 var org2 string 88 89 BeforeEach(func() { 90 org1 = helpers.NewOrgName() 91 org2 = helpers.NewOrgName() 92 helpers.CreateOrg(org1) 93 helpers.CreateOrg(org2) 94 95 isolationSegment1 = helpers.NewIsolationSegmentName() 96 isolationSegment2 = helpers.NewIsolationSegmentName() 97 isolationSegment3 = helpers.NewIsolationSegmentName() 98 99 Eventually(helpers.CF("create-isolation-segment", isolationSegment1)).Should(Exit(0)) 100 Eventually(helpers.CF("create-isolation-segment", isolationSegment2)).Should(Exit(0)) 101 Eventually(helpers.CF("create-isolation-segment", isolationSegment3)).Should(Exit(0)) 102 Eventually(helpers.CF("enable-org-isolation", org1, isolationSegment2)).Should(Exit(0)) 103 Eventually(helpers.CF("enable-org-isolation", org1, isolationSegment3)).Should(Exit(0)) 104 Eventually(helpers.CF("enable-org-isolation", org2, isolationSegment3)).Should(Exit(0)) 105 }) 106 107 AfterEach(func() { 108 helpers.QuickDeleteOrg(org1) 109 helpers.QuickDeleteOrg(org2) 110 }) 111 112 It("returns an ok and displays the table", func() { 113 userName, _ := helpers.GetCredentials() 114 session := helpers.CF("isolation-segments") 115 Eventually(session).Should(Say("Getting isolation segments as %s...", userName)) 116 Eventually(session).Should(Say("OK")) 117 Eventually(session).Should(Say("name\\s+orgs")) 118 Eventually(session).Should(Say("shared")) 119 Eventually(session).Should(Say("%s\\s+", isolationSegment1)) 120 Eventually(session).Should(Say("%s\\s+%s", isolationSegment2, org1)) 121 Eventually(session).Should(Say("%s\\s+%s, %s", isolationSegment3, org1, org2)) 122 Eventually(session).Should(Exit(0)) 123 }) 124 }) 125 }) 126 })