github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/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  	. "github.com/onsi/gomega/ghttp"
    10  )
    11  
    12  var _ = Describe("disable-org-isolation command", func() {
    13  	var organizationName string
    14  	var isolationSegmentName string
    15  
    16  	BeforeEach(func() {
    17  		organizationName = helpers.NewOrgName()
    18  		isolationSegmentName = helpers.NewIsolationSegmentName()
    19  	})
    20  
    21  	Describe("help", func() {
    22  		Context("when --help flag is set", func() {
    23  			It("Displays command usage to output", func() {
    24  				session := helpers.CF("disable-org-isolation", "--help")
    25  				Eventually(session).Should(Say("NAME:"))
    26  				Eventually(session).Should(Say("disable-org-isolation - Revoke an organization's entitlement to an isolation segment"))
    27  				Eventually(session).Should(Say("USAGE:"))
    28  				Eventually(session).Should(Say("cf disable-org-isolation ORG_NAME SEGMENT_NAME"))
    29  				Eventually(session).Should(Say("SEE ALSO:"))
    30  				Eventually(session).Should(Say("enable-org-isolation, isolation-segments"))
    31  				Eventually(session).Should(Exit(0))
    32  			})
    33  		})
    34  	})
    35  
    36  	Context("when the environment is not setup correctly", func() {
    37  		Context("when no API endpoint is set", func() {
    38  			BeforeEach(func() {
    39  				helpers.UnsetAPI()
    40  			})
    41  
    42  			It("fails with no API endpoint set message", func() {
    43  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
    44  				Eventually(session).Should(Say("FAILED"))
    45  				Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint."))
    46  				Eventually(session).Should(Exit(1))
    47  			})
    48  		})
    49  
    50  		Context("when the v3 api does not exist", func() {
    51  			var server *Server
    52  
    53  			BeforeEach(func() {
    54  				server = helpers.StartAndTargetServerWithoutV3API()
    55  			})
    56  
    57  			AfterEach(func() {
    58  				server.Close()
    59  			})
    60  
    61  			It("fails with error message that the minimum version is not met", func() {
    62  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
    63  				Eventually(session).Should(Say("FAILED"))
    64  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\."))
    65  				Eventually(session).Should(Exit(1))
    66  			})
    67  		})
    68  
    69  		Context("when the v3 api version is lower than the minimum version", func() {
    70  			var server *Server
    71  
    72  			BeforeEach(func() {
    73  				server = helpers.StartAndTargetServerWithV3Version("3.0.0")
    74  			})
    75  
    76  			AfterEach(func() {
    77  				server.Close()
    78  			})
    79  
    80  			It("fails with error message that the minimum version is not met", func() {
    81  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
    82  				Eventually(session).Should(Say("FAILED"))
    83  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\."))
    84  				Eventually(session).Should(Exit(1))
    85  			})
    86  		})
    87  
    88  		Context("when not logged in", func() {
    89  			BeforeEach(func() {
    90  				helpers.LogoutCF()
    91  			})
    92  
    93  			It("fails with not logged in message", func() {
    94  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
    95  				Eventually(session).Should(Say("FAILED"))
    96  				Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in."))
    97  				Eventually(session).Should(Exit(1))
    98  			})
    99  		})
   100  	})
   101  
   102  	Context("when the environment is set up correctly", func() {
   103  		var userName string
   104  
   105  		BeforeEach(func() {
   106  			helpers.LoginCF()
   107  			userName, _ = helpers.GetCredentials()
   108  		})
   109  
   110  		Context("when the org does not exist", func() {
   111  			BeforeEach(func() {
   112  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   113  			})
   114  
   115  			It("outputs an error and exits 1", func() {
   116  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
   117  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
   118  				Eventually(session).Should(Say("FAILED"))
   119  				Eventually(session.Err).Should(Say("Organization '%s' not found.", organizationName))
   120  				Eventually(session).Should(Exit(1))
   121  			})
   122  		})
   123  
   124  		Context("when the isolation segment does not exist", func() {
   125  			It("outputs an error and exits 1", 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("FAILED"))
   129  				Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName))
   130  				Eventually(session).Should(Exit(1))
   131  			})
   132  		})
   133  
   134  		Context("when the binding does not exist", func() {
   135  			BeforeEach(func() {
   136  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   137  				Eventually(helpers.CF("create-org", organizationName)).Should(Exit(0))
   138  			})
   139  
   140  			AfterEach(func() {
   141  				helpers.QuickDeleteOrg(organizationName)
   142  			})
   143  
   144  			It("outputs a warning and exists 0", func() {
   145  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
   146  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
   147  				Eventually(session).Should(Say("OK"))
   148  				Eventually(session).Should(Exit(0))
   149  
   150  				// Tests idempotence
   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  		Context("when everything exists", func() {
   159  			BeforeEach(func() {
   160  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   161  				Eventually(helpers.CF("create-org", organizationName)).Should(Exit(0))
   162  				Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0))
   163  			})
   164  
   165  			AfterEach(func() {
   166  				helpers.QuickDeleteOrg(organizationName)
   167  			})
   168  
   169  			It("displays OK", func() {
   170  				session := helpers.CF("disable-org-isolation", organizationName, isolationSegmentName)
   171  				Eventually(session).Should(Say("Removing entitlement to isolation segment %s from org %s as %s...", isolationSegmentName, organizationName, userName))
   172  				Eventually(session).Should(Say("OK"))
   173  				Eventually(session).Should(Exit(0))
   174  			})
   175  		})
   176  	})
   177  })