github.com/sleungcy/cli@v7.1.0+incompatible/integration/v7/isolated/set_space_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-space-isolation-segment command", func() {
    12  	var organizationName string
    13  	var spaceName string
    14  	var isolationSegmentName string
    15  
    16  	BeforeEach(func() {
    17  		organizationName = helpers.NewOrgName()
    18  		isolationSegmentName = helpers.NewIsolationSegmentName()
    19  		spaceName = helpers.NewSpaceName()
    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-space-isolation-segment", "--help")
    26  				Eventually(session).Should(Say("NAME:"))
    27  				Eventually(session).Should(Say("set-space-isolation-segment - Assign the isolation segment for a space"))
    28  				Eventually(session).Should(Say("USAGE:"))
    29  				Eventually(session).Should(Say("cf set-space-isolation-segment SPACE_NAME SEGMENT_NAME"))
    30  				Eventually(session).Should(Say("SEE ALSO:"))
    31  				Eventually(session).Should(Say("org, reset-space-isolation-segment, restart, set-org-default-isolation-segment, space"))
    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(true, false, ReadOnlyOrg, "set-space-isolation-segment", "space-name", "isolation-seg-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  			helpers.CreateOrg(organizationName)
    50  			helpers.TargetOrg(organizationName)
    51  		})
    52  
    53  		AfterEach(func() {
    54  			helpers.QuickDeleteOrg(organizationName)
    55  		})
    56  
    57  		When("the space does not exist", func() {
    58  			It("fails with space not found message", func() {
    59  				session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)
    60  				Eventually(session).Should(Say(`Updating isolation segment of space %s in org %s as %s\.\.\.`, spaceName, organizationName, userName))
    61  				Eventually(session).Should(Say("FAILED"))
    62  				Eventually(session.Err).Should(Say("Space '%s' not found.", spaceName))
    63  				Eventually(session).Should(Exit(1))
    64  			})
    65  		})
    66  
    67  		When("the space exists", func() {
    68  			BeforeEach(func() {
    69  				helpers.CreateSpace(spaceName)
    70  			})
    71  
    72  			When("the isolation segment does not exist", func() {
    73  				It("fails with isolation segment not found message", func() {
    74  					session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)
    75  					Eventually(session).Should(Say(`Updating isolation segment of space %s in org %s as %s\.\.\.`, spaceName, organizationName, userName))
    76  					Eventually(session).Should(Say("FAILED"))
    77  					Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName))
    78  					Eventually(session).Should(Exit(1))
    79  				})
    80  			})
    81  
    82  			When("the isolation segment exists", func() {
    83  				BeforeEach(func() {
    84  					Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
    85  				})
    86  
    87  				When("the isolation segment is entitled to the organization", func() {
    88  					BeforeEach(func() {
    89  						Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0))
    90  					})
    91  
    92  					It("displays OK", func() {
    93  						session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)
    94  						Eventually(session).Should(Say(`Updating isolation segment of space %s in org %s as %s\.\.\.`, spaceName, organizationName, userName))
    95  						Eventually(session).Should(Say("OK"))
    96  						Eventually(session).Should(Say("TIP: Restart applications in this space to relocate them to this isolation segment."))
    97  						Eventually(session).Should(Exit(0))
    98  					})
    99  
   100  					When("the isolation is already set to space", func() {
   101  						BeforeEach(func() {
   102  							Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0))
   103  						})
   104  
   105  						It("displays OK", func() {
   106  							session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)
   107  							Eventually(session).Should(Say(`Updating isolation segment of space %s in org %s as %s\.\.\.`, spaceName, organizationName, userName))
   108  							Eventually(session).Should(Say("OK"))
   109  							Eventually(session).Should(Say("TIP: Restart applications in this space to relocate them to this isolation segment."))
   110  							Eventually(session).Should(Exit(0))
   111  						})
   112  					})
   113  				})
   114  			})
   115  		})
   116  	})
   117  })