github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/isolated/reset_space_isolation_segment_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("reset-space-isolation-segment command", func() { 14 var organizationName string 15 var spaceName string 16 17 BeforeEach(func() { 18 helpers.SkipIfVersionLessThan(ccversion.MinVersionIsolationSegmentV3) 19 20 organizationName = helpers.NewOrgName() 21 spaceName = helpers.NewSpaceName() 22 }) 23 24 Describe("help", func() { 25 Context("when --help flag is set", func() { 26 It("Displays command usage to output", func() { 27 session := helpers.CF("reset-space-isolation-segment", "--help") 28 Eventually(session).Should(Say("NAME:")) 29 Eventually(session).Should(Say("reset-space-isolation-segment - Reset the space's isolation segment to the org default")) 30 Eventually(session).Should(Say("USAGE:")) 31 Eventually(session).Should(Say("cf reset-space-isolation-segment SPACE_NAME")) 32 Eventually(session).Should(Say("SEE ALSO:")) 33 Eventually(session).Should(Say("org, restart, space")) 34 Eventually(session).Should(Exit(0)) 35 }) 36 }) 37 }) 38 39 Context("when the environment is not setup correctly", func() { 40 Context("when no API endpoint is set", func() { 41 BeforeEach(func() { 42 helpers.UnsetAPI() 43 }) 44 45 It("fails with no API endpoint set message", func() { 46 session := helpers.CF("reset-space-isolation-segment", spaceName) 47 Eventually(session).Should(Say("FAILED")) 48 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 49 Eventually(session).Should(Exit(1)) 50 }) 51 }) 52 53 Context("when the v3 api does not exist", func() { 54 var server *Server 55 56 BeforeEach(func() { 57 server = helpers.StartAndTargetServerWithoutV3API() 58 }) 59 60 AfterEach(func() { 61 server.Close() 62 }) 63 64 It("fails with error message that the minimum version is not met", func() { 65 session := helpers.CF("reset-space-isolation-segment", spaceName) 66 Eventually(session).Should(Say("FAILED")) 67 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 68 Eventually(session).Should(Exit(1)) 69 }) 70 }) 71 72 Context("when the v3 api version is lower than the minimum version", func() { 73 var server *Server 74 75 BeforeEach(func() { 76 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0") 77 }) 78 79 AfterEach(func() { 80 server.Close() 81 }) 82 83 It("fails with error message that the minimum version is not met", func() { 84 session := helpers.CF("reset-space-isolation-segment", spaceName) 85 Eventually(session).Should(Say("FAILED")) 86 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 87 Eventually(session).Should(Exit(1)) 88 }) 89 }) 90 91 Context("when not logged in", func() { 92 BeforeEach(func() { 93 helpers.LogoutCF() 94 }) 95 96 It("fails with not logged in message", func() { 97 session := helpers.CF("reset-space-isolation-segment", spaceName) 98 Eventually(session).Should(Say("FAILED")) 99 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 100 Eventually(session).Should(Exit(1)) 101 }) 102 }) 103 104 Context("when there is no org set", func() { 105 BeforeEach(func() { 106 helpers.LoginCF() 107 }) 108 109 It("fails with no targeted org error message", func() { 110 session := helpers.CF("reset-space-isolation-segment", spaceName) 111 Eventually(session).Should(Say("FAILED")) 112 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 113 Eventually(session).Should(Exit(1)) 114 }) 115 }) 116 }) 117 118 Context("when the environment is set up correctly", func() { 119 var userName string 120 121 BeforeEach(func() { 122 helpers.LoginCF() 123 userName, _ = helpers.GetCredentials() 124 helpers.CreateOrg(organizationName) 125 helpers.TargetOrg(organizationName) 126 }) 127 128 AfterEach(func() { 129 helpers.QuickDeleteOrg(organizationName) 130 }) 131 132 Context("when the space does not exist", func() { 133 It("fails with space not found message", func() { 134 session := helpers.CF("reset-space-isolation-segment", spaceName) 135 Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName)) 136 Eventually(session).Should(Say("FAILED")) 137 Eventually(session.Err).Should(Say("Space '%s' not found.", spaceName)) 138 Eventually(session).Should(Exit(1)) 139 }) 140 }) 141 142 Context("when the space exists", func() { 143 BeforeEach(func() { 144 helpers.CreateSpace(spaceName) 145 isolationSegmentName := helpers.NewIsolationSegmentName() 146 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 147 Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0)) 148 Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0)) 149 }) 150 151 Context("when there is no default org isolation segment", func() { 152 It("resets the space isolation segment to the shared isolation segment", func() { 153 session := helpers.CF("reset-space-isolation-segment", spaceName) 154 Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName)) 155 156 Eventually(session).Should(Say("OK")) 157 Eventually(session).Should(Say("Applications in this space will be placed in the platform default isolation segment.")) 158 Eventually(session).Should(Say("Running applications need a restart to be moved there.")) 159 Eventually(session).Should(Exit(0)) 160 161 session = helpers.CF("space", spaceName) 162 Eventually(session).Should(Say("(?m)isolation segment:\\s*$")) 163 Eventually(session).Should(Exit(0)) 164 }) 165 }) 166 167 Context("when there is a default org isolation segment", func() { 168 var orgIsolationSegmentName string 169 170 BeforeEach(func() { 171 orgIsolationSegmentName = helpers.NewIsolationSegmentName() 172 Eventually(helpers.CF("create-isolation-segment", orgIsolationSegmentName)).Should(Exit(0)) 173 Eventually(helpers.CF("enable-org-isolation", organizationName, orgIsolationSegmentName)).Should(Exit(0)) 174 Eventually(helpers.CF("set-org-default-isolation-segment", organizationName, orgIsolationSegmentName)).Should(Exit(0)) 175 }) 176 177 It("resets the space isolation segment to the default org isolation segment", func() { 178 session := helpers.CF("reset-space-isolation-segment", spaceName) 179 Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName)) 180 181 Eventually(session).Should(Say("OK")) 182 Eventually(session).Should(Say("Applications in this space will be placed in isolation segment %s.", orgIsolationSegmentName)) 183 Eventually(session).Should(Say("Running applications need a restart to be moved there.")) 184 Eventually(session).Should(Exit(0)) 185 186 session = helpers.CF("space", spaceName) 187 Eventually(session).Should(Say("isolation segment:\\s+%s", orgIsolationSegmentName)) 188 Eventually(session).Should(Exit(0)) 189 }) 190 }) 191 }) 192 }) 193 })