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