github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/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 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 When("the environment is not setup correctly", func() { 40 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 When("the v3 api version is lower than the minimum version", func() { 54 var server *Server 55 56 BeforeEach(func() { 57 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion) 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 When("not logged in", func() { 73 BeforeEach(func() { 74 helpers.LogoutCF() 75 }) 76 77 It("fails with not logged in message", func() { 78 session := helpers.CF("reset-space-isolation-segment", spaceName) 79 Eventually(session).Should(Say("FAILED")) 80 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 81 Eventually(session).Should(Exit(1)) 82 }) 83 }) 84 85 When("there is no org set", func() { 86 BeforeEach(func() { 87 helpers.LoginCF() 88 }) 89 90 It("fails with no targeted org error message", func() { 91 session := helpers.CF("reset-space-isolation-segment", spaceName) 92 Eventually(session).Should(Say("FAILED")) 93 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 94 Eventually(session).Should(Exit(1)) 95 }) 96 }) 97 }) 98 99 When("the environment is set up correctly", func() { 100 var userName string 101 102 BeforeEach(func() { 103 helpers.LoginCF() 104 userName, _ = helpers.GetCredentials() 105 helpers.CreateOrg(organizationName) 106 helpers.TargetOrg(organizationName) 107 }) 108 109 AfterEach(func() { 110 helpers.QuickDeleteOrg(organizationName) 111 }) 112 113 When("the space does not exist", func() { 114 It("fails with space not found message", func() { 115 session := helpers.CF("reset-space-isolation-segment", spaceName) 116 Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName)) 117 Eventually(session).Should(Say("FAILED")) 118 Eventually(session.Err).Should(Say("Space '%s' not found.", spaceName)) 119 Eventually(session).Should(Exit(1)) 120 }) 121 }) 122 123 When("the space exists", func() { 124 BeforeEach(func() { 125 helpers.CreateSpace(spaceName) 126 isolationSegmentName := helpers.NewIsolationSegmentName() 127 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 128 Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0)) 129 Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0)) 130 }) 131 132 When("there is no default org isolation segment", func() { 133 It("resets the space isolation segment to the shared isolation segment", 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 137 Eventually(session).Should(Say("OK")) 138 Eventually(session).Should(Say("Applications in this space will be placed in the platform default isolation segment.")) 139 Eventually(session).Should(Say("Running applications need a restart to be moved there.")) 140 Eventually(session).Should(Exit(0)) 141 142 session = helpers.CF("space", spaceName) 143 Eventually(session).Should(Say(`(?m)isolation segment:\s*$`)) 144 Eventually(session).Should(Exit(0)) 145 }) 146 }) 147 148 When("there is a default org isolation segment", func() { 149 var orgIsolationSegmentName string 150 151 BeforeEach(func() { 152 orgIsolationSegmentName = helpers.NewIsolationSegmentName() 153 Eventually(helpers.CF("create-isolation-segment", orgIsolationSegmentName)).Should(Exit(0)) 154 Eventually(helpers.CF("enable-org-isolation", organizationName, orgIsolationSegmentName)).Should(Exit(0)) 155 Eventually(helpers.CF("set-org-default-isolation-segment", organizationName, orgIsolationSegmentName)).Should(Exit(0)) 156 }) 157 158 It("resets the space isolation segment to the default org isolation segment", func() { 159 session := helpers.CF("reset-space-isolation-segment", spaceName) 160 Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName)) 161 162 Eventually(session).Should(Say("OK")) 163 Eventually(session).Should(Say("Applications in this space will be placed in isolation segment %s.", orgIsolationSegmentName)) 164 Eventually(session).Should(Say("Running applications need a restart to be moved there.")) 165 Eventually(session).Should(Exit(0)) 166 167 session = helpers.CF("space", spaceName) 168 Eventually(session).Should(Say(`isolation segment:\s+%s`, orgIsolationSegmentName)) 169 Eventually(session).Should(Exit(0)) 170 }) 171 }) 172 }) 173 }) 174 })