github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/enable_org_isolation_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 ) 10 11 var _ = Describe("enable-org-isolation command", func() { 12 var organizationName string 13 var isolationSegmentName string 14 15 BeforeEach(func() { 16 organizationName = helpers.NewOrgName() 17 isolationSegmentName = helpers.NewIsolationSegmentName() 18 }) 19 20 Describe("help", func() { 21 When("--help flag is set", func() { 22 It("Displays command usage to output", func() { 23 session := helpers.CF("enable-org-isolation", "--help") 24 Eventually(session).Should(Say("NAME:")) 25 Eventually(session).Should(Say("enable-org-isolation - Entitle an organization to an isolation segment")) 26 Eventually(session).Should(Say("USAGE:")) 27 Eventually(session).Should(Say("cf enable-org-isolation ORG_NAME SEGMENT_NAME")) 28 Eventually(session).Should(Say("SEE ALSO:")) 29 Eventually(session).Should(Say("create-isolation-segment, isolation-segments, set-org-default-isolation-segment, set-space-isolation-segment")) 30 Eventually(session).Should(Exit(0)) 31 }) 32 }) 33 }) 34 35 When("the environment is not setup correctly", func() { 36 It("fails with the appropriate errors", func() { 37 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "enable-org-isolation", "org-name", "segment-name") 38 }) 39 }) 40 41 When("the environment is set up correctly", func() { 42 var userName string 43 44 BeforeEach(func() { 45 helpers.LoginCF() 46 userName, _ = helpers.GetCredentials() 47 }) 48 49 When("the isolation segment does not exist", func() { 50 It("fails with isolation segment not found message", func() { 51 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 52 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 53 Eventually(session).Should(Say("FAILED")) 54 Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName)) 55 Eventually(session).Should(Exit(1)) 56 }) 57 }) 58 59 When("the isolation segment exists", func() { 60 BeforeEach(func() { 61 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 62 }) 63 64 When("the organization does not exist", func() { 65 It("fails with organization not found message", func() { 66 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 67 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 68 Eventually(session).Should(Say("FAILED")) 69 Eventually(session.Err).Should(Say("Organization '%s' not found.", organizationName)) 70 Eventually(session).Should(Exit(1)) 71 }) 72 }) 73 74 When("the organization exists", func() { 75 BeforeEach(func() { 76 helpers.CreateOrg(organizationName) 77 helpers.TargetOrg(organizationName) 78 }) 79 80 AfterEach(func() { 81 helpers.QuickDeleteOrg(organizationName) 82 }) 83 84 It("displays OK", func() { 85 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 86 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 87 Eventually(session).Should(Say("OK")) 88 Eventually(session).Should(Exit(0)) 89 }) 90 91 When("the isolation is already enabled", func() { 92 BeforeEach(func() { 93 Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0)) 94 }) 95 96 It("displays OK", func() { 97 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 98 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 99 Eventually(session).Should(Say("OK")) 100 Eventually(session).Should(Exit(0)) 101 }) 102 }) 103 }) 104 }) 105 }) 106 })