github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/isolated/create_isolation_segment_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("create-isolation-segment command", func() { 14 var isolationSegmentName string 15 16 BeforeEach(func() { 17 helpers.SkipIfVersionLessThan(ccversion.MinVersionIsolationSegmentV3) 18 19 isolationSegmentName = helpers.NewIsolationSegmentName() 20 }) 21 22 Describe("help", func() { 23 Context("when --help flag is set", func() { 24 It("Displays command usage to output", func() { 25 session := helpers.CF("create-isolation-segment", "--help") 26 Eventually(session).Should(Say("NAME:")) 27 Eventually(session).Should(Say("create-isolation-segment - Create an isolation segment")) 28 Eventually(session).Should(Say("USAGE:")) 29 Eventually(session).Should(Say("cf create-isolation-segment SEGMENT_NAME")) 30 Eventually(session).Should(Say("NOTES:")) 31 Eventually(session).Should(Say("The isolation segment name must match the placement tag applied to the Diego cell.")) 32 Eventually(session).Should(Say("SEE ALSO:")) 33 Eventually(session).Should(Say("enable-org-isolation, isolation-segments")) 34 Eventually(session).Should(Exit(0)) 35 }) 36 }) 37 }) 38 39 Context("when the environment is not setup correctly", func() { 40 It("fails with the appropriate errors", func() { 41 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "create-isolation-segment", "isolation-seg-name") 42 }) 43 44 Context("when the v3 api does not exist", func() { 45 var server *Server 46 47 BeforeEach(func() { 48 server = helpers.StartAndTargetServerWithoutV3API() 49 }) 50 51 AfterEach(func() { 52 server.Close() 53 }) 54 55 It("fails with error message that the minimum version is not met", func() { 56 session := helpers.CF("create-isolation-segment", isolationSegmentName) 57 Eventually(session).Should(Say("FAILED")) 58 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 59 Eventually(session).Should(Exit(1)) 60 }) 61 }) 62 63 Context("when the v3 api version is lower than the minimum version", func() { 64 var server *Server 65 66 BeforeEach(func() { 67 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0") 68 }) 69 70 AfterEach(func() { 71 server.Close() 72 }) 73 74 It("fails with error message that the minimum version is not met", func() { 75 session := helpers.CF("create-isolation-segment", isolationSegmentName) 76 Eventually(session).Should(Say("FAILED")) 77 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 78 Eventually(session).Should(Exit(1)) 79 }) 80 }) 81 }) 82 83 Context("when the environment is set up correctly", func() { 84 BeforeEach(func() { 85 helpers.LoginCF() 86 }) 87 88 Context("when the isolation segment does not exist", func() { 89 It("creates the isolation segment", func() { 90 session := helpers.CF("create-isolation-segment", isolationSegmentName) 91 userName, _ := helpers.GetCredentials() 92 Eventually(session).Should(Say("Creating isolation segment %s as %s...", isolationSegmentName, userName)) 93 Eventually(session).Should(Say("OK")) 94 Eventually(session).Should(Exit(0)) 95 }) 96 }) 97 98 Context("when the isolation segment already exists", func() { 99 BeforeEach(func() { 100 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 101 }) 102 103 It("returns an ok", func() { 104 session := helpers.CF("create-isolation-segment", isolationSegmentName) 105 Eventually(session.Err).Should(Say("Isolation segment %s already exists", isolationSegmentName)) 106 Eventually(session).Should(Say("OK")) 107 Eventually(session).Should(Exit(0)) 108 }) 109 }) 110 }) 111 })