github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/integration/isolated/set_space_isolation_segment_command_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("set-space-isolation-segment command", func() { 12 var organizationName string 13 var spaceName string 14 var isolationSegmentName string 15 16 BeforeEach(func() { 17 organizationName = helpers.NewOrgName() 18 isolationSegmentName = helpers.IsolationSegmentName() 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("set-space-isolation-segment", "--help") 26 Eventually(session).Should(Say("NAME:")) 27 Eventually(session).Should(Say("set-space-isolation-segment - Assign the isolation segment that apps in a space are started in")) 28 Eventually(session).Should(Say("USAGE:")) 29 Eventually(session).Should(Say("cf set-space-isolation-segment SPACE_NAME SEGMENT_NAME")) 30 Eventually(session).Should(Say("SEE ALSO:")) 31 Eventually(session).Should(Say("org, reset-space-isolation-segment, 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("set-space-isolation-segment", spaceName, isolationSegmentName) 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("set-space-isolation-segment", spaceName, isolationSegmentName) 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("set-space-isolation-segment", spaceName, isolationSegmentName) 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("set-space-isolation-segment", spaceName, isolationSegmentName) 91 Eventually(session).Should(Say("Updating isolation segment 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 }) 102 103 Context("when the isolation segment does not exist", func() { 104 It("fails with isolation segment not found message", func() { 105 session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName) 106 Eventually(session).Should(Say("Updating isolation segment of space %s in org %s as %s...", spaceName, organizationName, userName)) 107 Eventually(session).Should(Say("FAILED")) 108 Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName)) 109 Eventually(session).Should(Exit(1)) 110 }) 111 }) 112 113 Context("when the isolation segment exists", func() { 114 BeforeEach(func() { 115 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 116 }) 117 118 Context("when the isolation segment is entitled to the organization", func() { 119 BeforeEach(func() { 120 Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0)) 121 }) 122 123 It("displays OK", func() { 124 session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName) 125 Eventually(session).Should(Say("Updating isolation segment of space %s in org %s as %s...", spaceName, organizationName, userName)) 126 Eventually(session).Should(Say("OK")) 127 Eventually(session).Should(Say("In order to move running applications to this isolation segment, they must be restarted.")) 128 Eventually(session).Should(Exit(0)) 129 }) 130 131 Context("when the isolation is already set to space", func() { 132 BeforeEach(func() { 133 Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0)) 134 }) 135 136 It("displays OK", func() { 137 session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName) 138 Eventually(session).Should(Say("Updating isolation segment of space %s in org %s as %s...", spaceName, organizationName, userName)) 139 Eventually(session).Should(Say("OK")) 140 Eventually(session).Should(Say("In order to move running applications to this isolation segment, they must be restarted.")) 141 Eventually(session).Should(Exit(0)) 142 }) 143 }) 144 }) 145 }) 146 }) 147 }) 148 })