github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/integration/isolated/reset_space_isolation_segment_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("reset-space-isolation-segment command", func() { 14 var organizationName string 15 var spaceName string 16 17 BeforeEach(func() { 18 organizationName = helpers.NewOrgName() 19 spaceName = helpers.NewSpaceName() 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("reset-space-isolation-segment", "--help") 26 Eventually(session).Should(Say("NAME:")) 27 Eventually(session).Should(Say("reset-space-isolation-segment - Reset the isolation segment assignment of a space to the org's default")) 28 Eventually(session).Should(Say("USAGE:")) 29 Eventually(session).Should(Say("cf reset-space-isolation-segment SPACE_NAME")) 30 Eventually(session).Should(Say("SEE ALSO:")) 31 Eventually(session).Should(Say("org, restart, space")) 32 Eventually(session).Should(Exit(0)) 33 }) 34 }) 35 }) 36 37 Context("when the environment is not setup correctly", func() { 38 Context("when no API endpoint is set", func() { 39 BeforeEach(func() { 40 helpers.UnsetAPI() 41 }) 42 43 It("fails with no API endpoint set message", func() { 44 session := helpers.CF("reset-space-isolation-segment", spaceName) 45 Eventually(session).Should(Say("FAILED")) 46 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 47 Eventually(session).Should(Exit(1)) 48 }) 49 }) 50 51 Context("when not logged in", func() { 52 BeforeEach(func() { 53 helpers.LogoutCF() 54 }) 55 56 It("fails with not logged in message", func() { 57 session := helpers.CF("reset-space-isolation-segment", spaceName) 58 Eventually(session).Should(Say("FAILED")) 59 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 60 Eventually(session).Should(Exit(1)) 61 }) 62 }) 63 64 Context("when there is no org set", func() { 65 BeforeEach(func() { 66 helpers.LoginCF() 67 }) 68 69 It("fails with no targeted org error message", func() { 70 session := helpers.CF("reset-space-isolation-segment", spaceName) 71 Eventually(session.Out).Should(Say("FAILED")) 72 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 73 Eventually(session).Should(Exit(1)) 74 }) 75 }) 76 }) 77 78 Context("when the environment is set up correctly", func() { 79 var userName string 80 81 BeforeEach(func() { 82 helpers.LoginCF() 83 userName, _ = helpers.GetCredentials() 84 helpers.CreateOrg(organizationName) 85 helpers.TargetOrg(organizationName) 86 }) 87 88 Context("when the space does not exist", func() { 89 It("fails with space not found message", func() { 90 session := helpers.CF("reset-space-isolation-segment", spaceName) 91 Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName)) 92 Eventually(session).Should(Say("FAILED")) 93 Eventually(session.Err).Should(Say("Space '%s' not found.", spaceName)) 94 Eventually(session).Should(Exit(1)) 95 }) 96 }) 97 98 Context("when the space exists", func() { 99 BeforeEach(func() { 100 helpers.CreateSpace(spaceName) 101 isolationSegmentName := helpers.IsolationSegmentName() 102 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 103 Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0)) 104 Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0)) 105 }) 106 107 Context("when there is no default org isolation segment", func() { 108 It("resets the space isolation segment to the shared isolation segment", func() { 109 session := helpers.CF("reset-space-isolation-segment", spaceName) 110 Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName)) 111 112 Eventually(session).Should(Say("OK")) 113 Eventually(session).Should(Say("Applications in this space will be placed in the platform default isolation segment.")) 114 Eventually(session).Should(Say("Running applications need a restart to be moved there.")) 115 Eventually(session).Should(Exit(0)) 116 117 Eventually(helpers.CF("space", spaceName)).Should(Say("(?m)isolation segment:\\s*$")) 118 }) 119 }) 120 121 Context("when there is a default org isolation segment", func() { 122 var orgGUID string 123 var orgIsolationSegmentName string 124 var orgIsolationSegmentGUID string 125 126 BeforeEach(func() { 127 orgIsolationSegmentName = helpers.IsolationSegmentName() 128 Eventually(helpers.CF("create-isolation-segment", orgIsolationSegmentName)).Should(Exit(0)) 129 Eventually(helpers.CF("enable-org-isolation", organizationName, orgIsolationSegmentName)).Should(Exit(0)) 130 orgIsolationSegmentGUID = helpers.GetIsolationSegmentGUID(orgIsolationSegmentName) 131 orgGUID = helpers.GetOrgGUID(organizationName) 132 133 Eventually(helpers.CF("curl", "-X", "PATCH", 134 fmt.Sprintf("/v3/organizations/%s/relationships/default_isolation_segment", orgGUID), 135 "-d", fmt.Sprintf(`{"data":{"guid":"%s"}`, orgIsolationSegmentGUID))).Should(Exit(0)) 136 }) 137 138 It("resets the space isolation segment to the default org isolation segment", func() { 139 session := helpers.CF("reset-space-isolation-segment", spaceName) 140 Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName)) 141 142 Eventually(session).Should(Say("OK")) 143 Eventually(session).Should(Say("Applications in this space will be placed in isolation segment %s.", orgIsolationSegmentName)) 144 Eventually(session).Should(Say("Running applications need a restart to be moved there.")) 145 Eventually(session).Should(Exit(0)) 146 147 Eventually(helpers.CF("space", spaceName)).Should(Say("isolation segment:\\s+%s", orgIsolationSegmentName)) 148 }) 149 }) 150 }) 151 }) 152 })