github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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 setup correctly", func() { 35 It("fails with the appropriate errors", func() { 36 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "reset-org-default-isolation-segment", "org-name") 37 }) 38 39 Context("when the v3 api does not exist", func() { 40 var server *Server 41 42 BeforeEach(func() { 43 server = helpers.StartAndTargetServerWithoutV3API() 44 }) 45 46 AfterEach(func() { 47 server.Close() 48 }) 49 50 It("fails with error message that the minimum version is not met", func() { 51 session := helpers.CF("reset-org-default-isolation-segment", orgName) 52 Eventually(session).Should(Say("FAILED")) 53 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 54 Eventually(session).Should(Exit(1)) 55 }) 56 }) 57 58 Context("when the v3 api version is lower than the minimum version", func() { 59 var server *Server 60 61 BeforeEach(func() { 62 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 63 }) 64 65 AfterEach(func() { 66 server.Close() 67 }) 68 69 It("fails with error message that the minimum version is not met", func() { 70 session := helpers.CF("reset-org-default-isolation-segment", orgName) 71 Eventually(session).Should(Say("FAILED")) 72 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 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 var userOrgName string 81 82 BeforeEach(func() { 83 helpers.LoginCF() 84 userName, _ = helpers.GetCredentials() 85 userOrgName = helpers.NewOrgName() 86 helpers.CreateOrg(userOrgName) 87 helpers.TargetOrg(userOrgName) 88 }) 89 90 AfterEach(func() { 91 helpers.QuickDeleteOrg(userOrgName) 92 }) 93 94 Context("when the org does not exist", func() { 95 It("fails with org not found message", func() { 96 session := helpers.CF("reset-org-default-isolation-segment", orgName) 97 Eventually(session).Should(Say("Resetting default isolation segment of org %s as %s\\.\\.\\.", orgName, userName)) 98 Eventually(session).Should(Say("FAILED")) 99 Eventually(session.Err).Should(Say("Organization '%s' not found\\.", orgName)) 100 Eventually(session).Should(Exit(1)) 101 }) 102 }) 103 104 Context("when the org exists", func() { 105 BeforeEach(func() { 106 helpers.CreateOrg(orgName) 107 }) 108 109 AfterEach(func() { 110 helpers.QuickDeleteOrg(orgName) 111 }) 112 113 Context("when the isolation segment is set as the org's default", func() { 114 BeforeEach(func() { 115 isolationSegmentName := helpers.NewIsolationSegmentName() 116 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 117 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName)).Should(Exit(0)) 118 Eventually(helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName)).Should(Exit(0)) 119 }) 120 121 It("displays OK", func() { 122 session := helpers.CF("reset-org-default-isolation-segment", orgName) 123 Eventually(session).Should(Say("Resetting default isolation segment of org %s as %s\\.\\.\\.", orgName, userName)) 124 Eventually(session).Should(Say("OK")) 125 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\\.")) 126 Eventually(session).Should(Say("Running applications need a restart to be moved there\\.")) 127 Eventually(session).Should(Exit(0)) 128 }) 129 }) 130 131 Context("when the org has no default isolation segment", func() { 132 It("displays OK", func() { 133 session := helpers.CF("reset-org-default-isolation-segment", orgName) 134 Eventually(session).Should(Say("Resetting default isolation segment of org %s as %s\\.\\.\\.", orgName, userName)) 135 Eventually(session).Should(Say("OK")) 136 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\\.")) 137 Eventually(session).Should(Say("Running applications need a restart to be moved there\\.")) 138 Eventually(session).Should(Exit(0)) 139 }) 140 }) 141 }) 142 }) 143 })