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