github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/isolated/disable_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("disable-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("disable-org-isolation", "--help") 28 Eventually(session).Should(Say("NAME:")) 29 Eventually(session).Should(Say("disable-org-isolation - Revoke an organization's entitlement to an isolation segment")) 30 Eventually(session).Should(Say("USAGE:")) 31 Eventually(session).Should(Say("cf disable-org-isolation ORG_NAME SEGMENT_NAME")) 32 Eventually(session).Should(Say("SEE ALSO:")) 33 Eventually(session).Should(Say("enable-org-isolation, isolation-segments")) 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, "disable-org-isolation", "org-name", "isolation-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("disable-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 org does not exist", func() { 73 BeforeEach(func() { 74 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 75 }) 76 77 It("outputs an error and exits 1", func() { 78 session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName) 79 Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName)) 80 Eventually(session).Should(Say("FAILED")) 81 Eventually(session.Err).Should(Say("Organization '%s' not found.", organizationName)) 82 Eventually(session).Should(Exit(1)) 83 }) 84 }) 85 86 When("the isolation segment does not exist", func() { 87 It("outputs an error and exits 1", func() { 88 session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName) 89 Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName)) 90 Eventually(session).Should(Say("FAILED")) 91 Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName)) 92 Eventually(session).Should(Exit(1)) 93 }) 94 }) 95 96 When("the binding does not exist", func() { 97 BeforeEach(func() { 98 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 99 Eventually(helpers.CF("create-org", organizationName)).Should(Exit(0)) 100 }) 101 102 AfterEach(func() { 103 helpers.QuickDeleteOrg(organizationName) 104 }) 105 106 It("outputs a warning and exists 0", func() { 107 session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName) 108 Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName)) 109 Eventually(session).Should(Say("OK")) 110 Eventually(session).Should(Exit(0)) 111 112 // Tests idempotence 113 session = helpers.CF("disable-org-isolation", organizationName, isolationSegmentName) 114 Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName)) 115 Eventually(session).Should(Say("OK")) 116 Eventually(session).Should(Exit(0)) 117 }) 118 }) 119 120 When("everything exists", func() { 121 BeforeEach(func() { 122 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 123 Eventually(helpers.CF("create-org", organizationName)).Should(Exit(0)) 124 Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0)) 125 }) 126 127 AfterEach(func() { 128 helpers.QuickDeleteOrg(organizationName) 129 }) 130 131 It("displays OK", func() { 132 session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName) 133 Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName)) 134 Eventually(session).Should(Say("OK")) 135 Eventually(session).Should(Exit(0)) 136 }) 137 }) 138 }) 139 })