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