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