github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/set_org_default_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 . "github.com/onsi/gomega/ghttp" 10 ) 11 12 var _ = Describe("set-org-default-isolation-segment command", func() { 13 var ( 14 orgName string 15 isolationSegmentName string 16 ) 17 18 BeforeEach(func() { 19 orgName = helpers.NewOrgName() 20 isolationSegmentName = helpers.NewIsolationSegmentName() 21 }) 22 23 Describe("help", func() { 24 Context("when --help flag is set", func() { 25 It("displays command usage to output", func() { 26 session := helpers.CF("set-org-default-isolation-segment", "--help") 27 Eventually(session).Should(Say("NAME:")) 28 Eventually(session).Should(Say("set-org-default-isolation-segment - Set the default isolation segment used for apps in spaces in an org")) 29 Eventually(session).Should(Say("USAGE:")) 30 Eventually(session).Should(Say("cf set-org-default-isolation-segment ORG_NAME SEGMENT_NAME")) 31 Eventually(session).Should(Say("SEE ALSO:")) 32 Eventually(session).Should(Say("org, set-space-isolation-segment")) 33 Eventually(session).Should(Exit(0)) 34 }) 35 }) 36 }) 37 38 Context("when the environment is not set-up correctly", func() { 39 Context("when no API endpoint is set", func() { 40 BeforeEach(func() { 41 helpers.UnsetAPI() 42 }) 43 44 It("fails with no API endpoint set message", func() { 45 session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName) 46 Eventually(session).Should(Say("FAILED")) 47 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 48 Eventually(session).Should(Exit(1)) 49 }) 50 }) 51 52 Context("when the v3 api does not exist", func() { 53 var server *Server 54 55 BeforeEach(func() { 56 server = helpers.StartAndTargetServerWithoutV3API() 57 }) 58 59 AfterEach(func() { 60 server.Close() 61 }) 62 63 It("fails with error message that the minimum version is not met", func() { 64 session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName) 65 Eventually(session).Should(Say("FAILED")) 66 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 67 Eventually(session).Should(Exit(1)) 68 }) 69 }) 70 71 Context("when the v3 api version is lower than the minimum version", func() { 72 var server *Server 73 74 BeforeEach(func() { 75 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 76 }) 77 78 AfterEach(func() { 79 server.Close() 80 }) 81 82 It("fails with error message that the minimum version is not met", func() { 83 session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName) 84 Eventually(session).Should(Say("FAILED")) 85 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 86 Eventually(session).Should(Exit(1)) 87 }) 88 }) 89 90 Context("when not logged in", func() { 91 BeforeEach(func() { 92 helpers.LogoutCF() 93 }) 94 95 It("fails with not logged in message", func() { 96 session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName) 97 Eventually(session).Should(Say("FAILED")) 98 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 99 Eventually(session).Should(Exit(1)) 100 }) 101 }) 102 }) 103 104 Context("when the environment is set-up correctly", func() { 105 var userName string 106 107 BeforeEach(func() { 108 helpers.LoginCF() 109 userName, _ = helpers.GetCredentials() 110 }) 111 112 Context("when the org does not exist", func() { 113 It("fails with org not found message", func() { 114 session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName) 115 Eventually(session).Should(Say("Setting isolation segment %s to default on org %s as %s\\.\\.\\.", isolationSegmentName, orgName, userName)) 116 Eventually(session).Should(Say("FAILED")) 117 Eventually(session.Err).Should(Say("Organization '%s' not found\\.", orgName)) 118 Eventually(session).Should(Exit(1)) 119 }) 120 }) 121 122 Context("when the org exists", func() { 123 BeforeEach(func() { 124 helpers.CreateOrg(orgName) 125 }) 126 127 AfterEach(func() { 128 helpers.QuickDeleteOrg(orgName) 129 }) 130 131 Context("when the isolation segment does not exist", func() { 132 It("fails with isolation segment not found message", func() { 133 session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName) 134 Eventually(session).Should(Say("Setting isolation segment %s to default on org %s as %s\\.\\.\\.", isolationSegmentName, orgName, userName)) 135 Eventually(session).Should(Say("FAILED")) 136 Eventually(session.Err).Should(Say("Isolation segment '%s' not found\\.", isolationSegmentName)) 137 Eventually(session).Should(Exit(1)) 138 }) 139 }) 140 141 Context("when the isolation segment exists", func() { 142 BeforeEach(func() { 143 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 144 }) 145 146 Context("when the isolation segment is entitled to the organization", func() { 147 BeforeEach(func() { 148 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName)).Should(Exit(0)) 149 }) 150 151 It("displays OK", func() { 152 session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName) 153 Eventually(session).Should(Say("Setting isolation segment %s to default on org %s as %s\\.\\.\\.", isolationSegmentName, orgName, userName)) 154 Eventually(session).Should(Say("OK")) 155 Eventually(session).Should(Say("In order to move running applications to this isolation segment, they must be restarted\\.")) 156 Eventually(session).Should(Exit(0)) 157 }) 158 159 Context("when the isolation segment is already set as the org's default", func() { 160 BeforeEach(func() { 161 Eventually(helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName)).Should(Exit(0)) 162 }) 163 164 It("displays OK", func() { 165 session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName) 166 Eventually(session).Should(Say("Setting isolation segment %s to default on org %s as %s\\.\\.\\.", isolationSegmentName, orgName, userName)) 167 Eventually(session).Should(Say("OK")) 168 Eventually(session).Should(Say("In order to move running applications to this isolation segment, they must be restarted\\.")) 169 Eventually(session).Should(Exit(0)) 170 }) 171 }) 172 }) 173 }) 174 }) 175 }) 176 })