github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/integration/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.IsolationSegmentName() 18 }) 19 20 Describe("help", func() { 21 Context("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-space-isolation-segment")) 30 Eventually(session).Should(Exit(0)) 31 }) 32 }) 33 }) 34 35 Context("when the environment is not setup correctly", func() { 36 Context("when no API endpoint is set", func() { 37 BeforeEach(func() { 38 helpers.UnsetAPI() 39 }) 40 41 It("fails with no API endpoint set message", func() { 42 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 43 Eventually(session).Should(Say("FAILED")) 44 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 45 Eventually(session).Should(Exit(1)) 46 }) 47 }) 48 49 Context("when not logged in", func() { 50 BeforeEach(func() { 51 helpers.LogoutCF() 52 }) 53 54 It("fails with not logged in message", func() { 55 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 56 Eventually(session).Should(Say("FAILED")) 57 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 58 Eventually(session).Should(Exit(1)) 59 }) 60 }) 61 }) 62 63 Context("when the environment is set up correctly", func() { 64 var userName string 65 66 BeforeEach(func() { 67 helpers.LoginCF() 68 userName, _ = helpers.GetCredentials() 69 }) 70 71 Context("when the isolation segment does not exist", func() { 72 It("fails with isolation segment not found message", func() { 73 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 74 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 75 Eventually(session).Should(Say("FAILED")) 76 Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName)) 77 Eventually(session).Should(Exit(1)) 78 }) 79 }) 80 81 Context("when the isolation segment exists", func() { 82 BeforeEach(func() { 83 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 84 }) 85 86 Context("when the organization does not exist", func() { 87 It("fails with organization not found message", func() { 88 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 89 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 90 Eventually(session).Should(Say("FAILED")) 91 Eventually(session.Err).Should(Say("Organization '%s' not found.", organizationName)) 92 Eventually(session).Should(Exit(1)) 93 }) 94 }) 95 96 Context("when the organization exists", func() { 97 BeforeEach(func() { 98 helpers.CreateOrg(organizationName) 99 helpers.TargetOrg(organizationName) 100 }) 101 102 It("displays OK", func() { 103 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 104 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 105 Eventually(session).Should(Say("OK")) 106 Eventually(session).Should(Exit(0)) 107 }) 108 109 Context("when the isolation is already enabled", func() { 110 BeforeEach(func() { 111 Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0)) 112 }) 113 114 It("displays OK", func() { 115 session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName) 116 Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName)) 117 Eventually(session).Should(Say("OK")) 118 Eventually(session).Should(Exit(0)) 119 }) 120 }) 121 }) 122 }) 123 }) 124 })