github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/set_org_default_isolation_segment_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("set-org-default-isolation-segment command", func() {
    12  	var (
    13  		orgName              string
    14  		isolationSegmentName string
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		orgName = helpers.NewOrgName()
    19  		isolationSegmentName = helpers.NewIsolationSegmentName()
    20  	})
    21  
    22  	Describe("help", func() {
    23  		When("--help flag is set", func() {
    24  			It("displays command usage to output", func() {
    25  				session := helpers.CF("set-org-default-isolation-segment", "--help")
    26  				Eventually(session).Should(Say("NAME:"))
    27  				Eventually(session).Should(Say("set-org-default-isolation-segment - Set the default isolation segment used for apps in spaces in an org"))
    28  				Eventually(session).Should(Say("USAGE:"))
    29  				Eventually(session).Should(Say("cf set-org-default-isolation-segment ORG_NAME SEGMENT_NAME"))
    30  				Eventually(session).Should(Say("SEE ALSO:"))
    31  				Eventually(session).Should(Say("org, set-space-isolation-segment"))
    32  				Eventually(session).Should(Exit(0))
    33  			})
    34  		})
    35  	})
    36  
    37  	When("the environment is not setup correctly", func() {
    38  		It("fails with the appropriate errors", func() {
    39  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "set-org-default-isolation-segment", "orgname", "segment-name")
    40  		})
    41  	})
    42  
    43  	When("the environment is set-up correctly", func() {
    44  		var userName string
    45  
    46  		BeforeEach(func() {
    47  			helpers.LoginCF()
    48  			userName, _ = helpers.GetCredentials()
    49  		})
    50  
    51  		When("the org does not exist", func() {
    52  			It("fails with org not found message", func() {
    53  				session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName)
    54  				Eventually(session).Should(Say(`Setting isolation segment %s to default on org %s as %s\.\.\.`, isolationSegmentName, orgName, userName))
    55  				Eventually(session).Should(Say("FAILED"))
    56  				Eventually(session.Err).Should(Say(`Organization '%s' not found\.`, orgName))
    57  				Eventually(session).Should(Exit(1))
    58  			})
    59  		})
    60  
    61  		When("the org exists", func() {
    62  			BeforeEach(func() {
    63  				helpers.CreateOrg(orgName)
    64  			})
    65  
    66  			AfterEach(func() {
    67  				helpers.QuickDeleteOrg(orgName)
    68  			})
    69  
    70  			When("the isolation segment does not exist", func() {
    71  				It("fails with isolation segment not found message", func() {
    72  					session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName)
    73  					Eventually(session).Should(Say(`Setting isolation segment %s to default on org %s as %s\.\.\.`, isolationSegmentName, orgName, userName))
    74  					Eventually(session).Should(Say("FAILED"))
    75  					Eventually(session.Err).Should(Say(`Isolation segment '%s' not found\.`, isolationSegmentName))
    76  					Eventually(session).Should(Exit(1))
    77  				})
    78  			})
    79  
    80  			When("the isolation segment exists", func() {
    81  				BeforeEach(func() {
    82  					Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
    83  				})
    84  
    85  				When("the isolation segment is entitled to the organization", func() {
    86  					BeforeEach(func() {
    87  						Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName)).Should(Exit(0))
    88  					})
    89  
    90  					It("displays OK", func() {
    91  						session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName)
    92  						Eventually(session).Should(Say(`Setting isolation segment %s to default on org %s as %s\.\.\.`, isolationSegmentName, orgName, userName))
    93  						Eventually(session).Should(Say("OK"))
    94  						Eventually(session).Should(Say("TIP: Restart applications in this organization to relocate them to this isolation segment."))
    95  						Eventually(session).Should(Exit(0))
    96  					})
    97  
    98  					When("the isolation segment is already set as the org's default", func() {
    99  						BeforeEach(func() {
   100  							Eventually(helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName)).Should(Exit(0))
   101  						})
   102  
   103  						It("displays OK", func() {
   104  							session := helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentName)
   105  							Eventually(session).Should(Say(`Setting isolation segment %s to default on org %s as %s\.\.\.`, isolationSegmentName, orgName, userName))
   106  							Eventually(session).Should(Say("OK"))
   107  							Eventually(session).Should(Say("TIP: Restart applications in this organization to relocate them to this isolation segment."))
   108  							Eventually(session).Should(Exit(0))
   109  						})
   110  					})
   111  				})
   112  			})
   113  		})
   114  	})
   115  })