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