github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/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  		Context("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  	Context("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  		Context("when the v3 api does not exist", func() {
    45  			var server *Server
    46  
    47  			BeforeEach(func() {
    48  				server = helpers.StartAndTargetServerWithoutV3API()
    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  		Context("when the v3 api version is lower than the minimum version", func() {
    64  			var server *Server
    65  
    66  			BeforeEach(func() {
    67  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0")
    68  			})
    69  
    70  			AfterEach(func() {
    71  				server.Close()
    72  			})
    73  
    74  			It("fails with error message that the minimum version is not met", func() {
    75  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
    76  				Eventually(session).Should(Say("FAILED"))
    77  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\."))
    78  				Eventually(session).Should(Exit(1))
    79  			})
    80  		})
    81  	})
    82  
    83  	Context("when the environment is set up correctly", func() {
    84  		var userName string
    85  
    86  		BeforeEach(func() {
    87  			helpers.LoginCF()
    88  			userName, _ = helpers.GetCredentials()
    89  		})
    90  
    91  		Context("when the org does not exist", func() {
    92  			BeforeEach(func() {
    93  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
    94  			})
    95  
    96  			It("outputs an error and exits 1", func() {
    97  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
    98  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
    99  				Eventually(session).Should(Say("FAILED"))
   100  				Eventually(session.Err).Should(Say("Organization '%s' not found.", organizationName))
   101  				Eventually(session).Should(Exit(1))
   102  			})
   103  		})
   104  
   105  		Context("when the isolation segment does not exist", func() {
   106  			It("outputs an error and exits 1", 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("FAILED"))
   110  				Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName))
   111  				Eventually(session).Should(Exit(1))
   112  			})
   113  		})
   114  
   115  		Context("when the binding does not exist", func() {
   116  			BeforeEach(func() {
   117  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   118  				Eventually(helpers.CF("create-org", organizationName)).Should(Exit(0))
   119  			})
   120  
   121  			AfterEach(func() {
   122  				helpers.QuickDeleteOrg(organizationName)
   123  			})
   124  
   125  			It("outputs a warning and exists 0", func() {
   126  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
   127  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
   128  				Eventually(session).Should(Say("OK"))
   129  				Eventually(session).Should(Exit(0))
   130  
   131  				// Tests idempotence
   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  		Context("when everything exists", func() {
   140  			BeforeEach(func() {
   141  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   142  				Eventually(helpers.CF("create-org", organizationName)).Should(Exit(0))
   143  				Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0))
   144  			})
   145  
   146  			AfterEach(func() {
   147  				helpers.QuickDeleteOrg(organizationName)
   148  			})
   149  
   150  			It("displays OK", func() {
   151  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
   152  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
   153  				Eventually(session).Should(Say("OK"))
   154  				Eventually(session).Should(Exit(0))
   155  			})
   156  		})
   157  	})
   158  })