github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/disable_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("disable-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("disable-org-isolation", "--help")
    24  				Eventually(session).Should(Say("NAME:"))
    25  				Eventually(session).Should(Say("disable-org-isolation - Revoke an organization's entitlement to an isolation segment"))
    26  				Eventually(session).Should(Say("USAGE:"))
    27  				Eventually(session).Should(Say("cf disable-org-isolation ORG_NAME SEGMENT_NAME"))
    28  				Eventually(session).Should(Say("SEE ALSO:"))
    29  				Eventually(session).Should(Say("enable-org-isolation, isolation-segments"))
    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, "disable-org-isolation", "org-name", "isolation-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 org does not exist", func() {
    50  			BeforeEach(func() {
    51  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
    52  			})
    53  
    54  			It("outputs an error and exits 1", func() {
    55  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
    56  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
    57  				Eventually(session).Should(Say("FAILED"))
    58  				Eventually(session.Err).Should(Say("Organization '%s' not found.", organizationName))
    59  				Eventually(session).Should(Exit(1))
    60  			})
    61  		})
    62  
    63  		When("the isolation segment does not exist", func() {
    64  			It("outputs an error and exits 1", func() {
    65  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
    66  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
    67  				Eventually(session).Should(Say("FAILED"))
    68  				Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName))
    69  				Eventually(session).Should(Exit(1))
    70  			})
    71  		})
    72  
    73  		When("the binding does not exist", func() {
    74  			BeforeEach(func() {
    75  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
    76  				Eventually(helpers.CF("create-org", organizationName)).Should(Exit(0))
    77  			})
    78  
    79  			AfterEach(func() {
    80  				helpers.QuickDeleteOrg(organizationName)
    81  			})
    82  
    83  			It("outputs a warning and exists 0", func() {
    84  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
    85  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
    86  				Eventually(session).Should(Say("OK"))
    87  				Eventually(session).Should(Exit(0))
    88  
    89  				// Tests idempotence
    90  				session = helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
    91  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
    92  				Eventually(session).Should(Say("OK"))
    93  				Eventually(session).Should(Exit(0))
    94  			})
    95  		})
    96  
    97  		When("everything exists", func() {
    98  			BeforeEach(func() {
    99  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   100  				Eventually(helpers.CF("create-org", organizationName)).Should(Exit(0))
   101  				Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0))
   102  			})
   103  
   104  			AfterEach(func() {
   105  				helpers.QuickDeleteOrg(organizationName)
   106  			})
   107  
   108  			It("displays OK", func() {
   109  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
   110  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
   111  				Eventually(session).Should(Say("OK"))
   112  				Eventually(session).Should(Exit(0))
   113  			})
   114  		})
   115  	})
   116  })