github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/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 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 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 When("the v3 api version is lower than the minimum version", func() { 45 var server *Server 46 47 BeforeEach(func() { 48 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion) 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 64 When("the environment is set up correctly", func() { 65 var userName string 66 67 BeforeEach(func() { 68 helpers.LoginCF() 69 userName, _ = helpers.GetCredentials() 70 }) 71 72 When("the isolation segment does not exist", func() { 73 It("fails with isolation segment not found message", func() { 74 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 75 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 76 Eventually(session).Should(Say("FAILED")) 77 Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName)) 78 Eventually(session).Should(Exit(1)) 79 }) 80 }) 81 82 When("the isolation segment exists", func() { 83 BeforeEach(func() { 84 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 85 }) 86 87 When("the organization does not exist", func() { 88 It("fails with organization not found message", func() { 89 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 90 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 91 Eventually(session).Should(Say("FAILED")) 92 Eventually(session.Err).Should(Say("Organization '%s' not found.", organizationName)) 93 Eventually(session).Should(Exit(1)) 94 }) 95 }) 96 97 When("the organization exists", func() { 98 BeforeEach(func() { 99 helpers.CreateOrg(organizationName) 100 helpers.TargetOrg(organizationName) 101 }) 102 103 AfterEach(func() { 104 helpers.QuickDeleteOrg(organizationName) 105 }) 106 107 It("displays OK", 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("OK")) 111 Eventually(session).Should(Exit(0)) 112 }) 113 114 When("the isolation is already enabled", func() { 115 BeforeEach(func() { 116 Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0)) 117 }) 118 119 It("displays OK", func() { 120 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 121 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 122 Eventually(session).Should(Say("OK")) 123 Eventually(session).Should(Exit(0)) 124 }) 125 }) 126 }) 127 }) 128 }) 129 })