github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/isolated/set_space_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("set-space-isolation-segment command", func() { 14 var organizationName string 15 var spaceName string 16 var isolationSegmentName string 17 18 BeforeEach(func() { 19 helpers.SkipIfVersionLessThan(ccversion.MinVersionIsolationSegmentV3) 20 21 organizationName = helpers.NewOrgName() 22 isolationSegmentName = helpers.NewIsolationSegmentName() 23 spaceName = helpers.NewSpaceName() 24 }) 25 26 Describe("help", func() { 27 Context("when --help flag is set", func() { 28 It("Displays command usage to output", func() { 29 session := helpers.CF("set-space-isolation-segment", "--help") 30 Eventually(session).Should(Say("NAME:")) 31 Eventually(session).Should(Say("set-space-isolation-segment - Assign the isolation segment for a space")) 32 Eventually(session).Should(Say("USAGE:")) 33 Eventually(session).Should(Say("cf set-space-isolation-segment SPACE_NAME SEGMENT_NAME")) 34 Eventually(session).Should(Say("SEE ALSO:")) 35 Eventually(session).Should(Say("org, reset-space-isolation-segment, restart, set-org-default-isolation-segment, space")) 36 Eventually(session).Should(Exit(0)) 37 }) 38 }) 39 }) 40 41 Context("when the environment is not setup correctly", func() { 42 It("fails with the appropriate errors", func() { 43 helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "set-space-isolation-segment", "space-name", "isolation-seg-name") 44 }) 45 46 Context("when the v3 api does not exist", func() { 47 var server *Server 48 49 BeforeEach(func() { 50 server = helpers.StartAndTargetServerWithoutV3API() 51 }) 52 53 AfterEach(func() { 54 server.Close() 55 }) 56 57 It("fails with error message that the minimum version is not met", func() { 58 session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName) 59 Eventually(session).Should(Say("FAILED")) 60 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 61 Eventually(session).Should(Exit(1)) 62 }) 63 }) 64 65 Context("when the v3 api version is lower than the minimum version", func() { 66 var server *Server 67 68 BeforeEach(func() { 69 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0") 70 }) 71 72 AfterEach(func() { 73 server.Close() 74 }) 75 76 It("fails with error message that the minimum version is not met", func() { 77 session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName) 78 Eventually(session).Should(Say("FAILED")) 79 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 80 Eventually(session).Should(Exit(1)) 81 }) 82 }) 83 }) 84 85 Context("when the environment is set up correctly", func() { 86 var userName string 87 88 BeforeEach(func() { 89 helpers.LoginCF() 90 userName, _ = helpers.GetCredentials() 91 helpers.CreateOrg(organizationName) 92 helpers.TargetOrg(organizationName) 93 }) 94 95 AfterEach(func() { 96 helpers.QuickDeleteOrg(organizationName) 97 }) 98 99 Context("when the space does not exist", func() { 100 It("fails with space not found message", func() { 101 session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName) 102 Eventually(session).Should(Say("Updating isolation segment of space %s in org %s as %s\\.\\.\\.", spaceName, organizationName, userName)) 103 Eventually(session).Should(Say("FAILED")) 104 Eventually(session.Err).Should(Say("Space '%s' not found.", spaceName)) 105 Eventually(session).Should(Exit(1)) 106 }) 107 }) 108 109 Context("when the space exists", func() { 110 BeforeEach(func() { 111 helpers.CreateSpace(spaceName) 112 }) 113 114 Context("when the isolation segment does not exist", func() { 115 It("fails with isolation segment not found message", func() { 116 session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName) 117 Eventually(session).Should(Say("Updating isolation segment of space %s in org %s as %s\\.\\.\\.", spaceName, organizationName, userName)) 118 Eventually(session).Should(Say("FAILED")) 119 Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName)) 120 Eventually(session).Should(Exit(1)) 121 }) 122 }) 123 124 Context("when the isolation segment exists", func() { 125 BeforeEach(func() { 126 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 127 }) 128 129 Context("when the isolation segment is entitled to the organization", func() { 130 BeforeEach(func() { 131 Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0)) 132 }) 133 134 It("displays OK", func() { 135 session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName) 136 Eventually(session).Should(Say("Updating isolation segment of space %s in org %s as %s\\.\\.\\.", spaceName, organizationName, userName)) 137 Eventually(session).Should(Say("OK")) 138 Eventually(session).Should(Say("In order to move running applications to this isolation segment, they must be restarted.")) 139 Eventually(session).Should(Exit(0)) 140 }) 141 142 Context("when the isolation is already set to space", func() { 143 BeforeEach(func() { 144 Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0)) 145 }) 146 147 It("displays OK", func() { 148 session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName) 149 Eventually(session).Should(Say("Updating isolation segment of space %s in org %s as %s\\.\\.\\.", spaceName, organizationName, userName)) 150 Eventually(session).Should(Say("OK")) 151 Eventually(session).Should(Say("In order to move running applications to this isolation segment, they must be restarted.")) 152 Eventually(session).Should(Exit(0)) 153 }) 154 }) 155 }) 156 }) 157 }) 158 }) 159 })