github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/isolated/reset_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("reset-org-default-isolation-segment command", func() { 14 var orgName string 15 16 BeforeEach(func() { 17 helpers.SkipIfVersionLessThan(ccversion.MinVersionIsolationSegmentV3) 18 19 orgName = helpers.NewOrgName() 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("reset-org-default-isolation-segment", "--help") 26 Eventually(session).Should(Say("NAME:")) 27 Eventually(session).Should(Say("reset-org-default-isolation-segment - Reset the default isolation segment used for apps in spaces of an org")) 28 Eventually(session).Should(Say("USAGE:")) 29 Eventually(session).Should(Say("cf reset-org-default-isolation-segment ORG_NAME")) 30 Eventually(session).Should(Say("SEE ALSO:")) 31 Eventually(session).Should(Say("org, restart")) 32 Eventually(session).Should(Exit(0)) 33 }) 34 }) 35 }) 36 37 Context("when the environment is not setup correctly", func() { 38 It("fails with the appropriate errors", func() { 39 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "reset-org-default-isolation-segment", "org-name") 40 }) 41 42 Context("when the v3 api does not exist", func() { 43 var server *Server 44 45 BeforeEach(func() { 46 server = helpers.StartAndTargetServerWithoutV3API() 47 }) 48 49 AfterEach(func() { 50 server.Close() 51 }) 52 53 It("fails with error message that the minimum version is not met", func() { 54 session := helpers.CF("reset-org-default-isolation-segment", orgName) 55 Eventually(session).Should(Say("FAILED")) 56 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 57 Eventually(session).Should(Exit(1)) 58 }) 59 }) 60 61 Context("when the v3 api version is lower than the minimum version", func() { 62 var server *Server 63 64 BeforeEach(func() { 65 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0") 66 }) 67 68 AfterEach(func() { 69 server.Close() 70 }) 71 72 It("fails with error message that the minimum version is not met", func() { 73 session := helpers.CF("reset-org-default-isolation-segment", orgName) 74 Eventually(session).Should(Say("FAILED")) 75 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 76 Eventually(session).Should(Exit(1)) 77 }) 78 }) 79 }) 80 81 Context("when the environment is set-up correctly", func() { 82 var userName string 83 var userOrgName string 84 85 BeforeEach(func() { 86 helpers.LoginCF() 87 userName, _ = helpers.GetCredentials() 88 userOrgName = helpers.NewOrgName() 89 helpers.CreateOrg(userOrgName) 90 helpers.TargetOrg(userOrgName) 91 }) 92 93 AfterEach(func() { 94 helpers.QuickDeleteOrg(userOrgName) 95 }) 96 97 Context("when the org does not exist", func() { 98 It("fails with org not found message", func() { 99 session := helpers.CF("reset-org-default-isolation-segment", orgName) 100 Eventually(session).Should(Say("Resetting default isolation segment of org %s as %s\\.\\.\\.", orgName, userName)) 101 Eventually(session).Should(Say("FAILED")) 102 Eventually(session.Err).Should(Say("Organization '%s' not found\\.", orgName)) 103 Eventually(session).Should(Exit(1)) 104 }) 105 }) 106 107 Context("when the org exists", func() { 108 BeforeEach(func() { 109 helpers.CreateOrg(orgName) 110 }) 111 112 AfterEach(func() { 113 helpers.QuickDeleteOrg(orgName) 114 }) 115 116 Context("when the isolation segment is set as the org's default", func() { 117 BeforeEach(func() { 118 isolationSegmentName := helpers.NewIsolationSegmentName() 119 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 120 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName)).Should(Exit(0)) 121 Eventually(helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName)).Should(Exit(0)) 122 }) 123 124 It("displays OK", func() { 125 session := helpers.CF("reset-org-default-isolation-segment", orgName) 126 Eventually(session).Should(Say("Resetting default isolation segment of org %s as %s\\.\\.\\.", orgName, userName)) 127 Eventually(session).Should(Say("OK")) 128 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\\.")) 129 Eventually(session).Should(Say("Running applications need a restart to be moved there\\.")) 130 Eventually(session).Should(Exit(0)) 131 }) 132 }) 133 134 Context("when the org has no default isolation segment", func() { 135 It("displays OK", func() { 136 session := helpers.CF("reset-org-default-isolation-segment", orgName) 137 Eventually(session).Should(Say("Resetting default isolation segment of org %s as %s\\.\\.\\.", orgName, userName)) 138 Eventually(session).Should(Say("OK")) 139 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\\.")) 140 Eventually(session).Should(Say("Running applications need a restart to be moved there\\.")) 141 Eventually(session).Should(Exit(0)) 142 }) 143 }) 144 }) 145 }) 146 })