github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/isolated/set_space_isolation_segment_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("set-space-isolation-segment command", func() {
    14  	var organizationName string
    15  	var spaceName string
    16  	var isolationSegmentName string
    17  
    18  	BeforeEach(func() {
    19  		helpers.SkipIfVersionLessThan(ccversion.MinVersionIsolationSegmentV3)
    20  
    21  		organizationName = helpers.NewOrgName()
    22  		isolationSegmentName = helpers.NewIsolationSegmentName()
    23  		spaceName = helpers.NewSpaceName()
    24  	})
    25  
    26  	Describe("help", func() {
    27  		When("--help flag is set", func() {
    28  			It("Displays command usage to output", func() {
    29  				session := helpers.CF("set-space-isolation-segment", "--help")
    30  				Eventually(session).Should(Say("NAME:"))
    31  				Eventually(session).Should(Say("set-space-isolation-segment - Assign the isolation segment for a space"))
    32  				Eventually(session).Should(Say("USAGE:"))
    33  				Eventually(session).Should(Say("cf set-space-isolation-segment SPACE_NAME SEGMENT_NAME"))
    34  				Eventually(session).Should(Say("SEE ALSO:"))
    35  				Eventually(session).Should(Say("org, reset-space-isolation-segment, restart, set-org-default-isolation-segment, space"))
    36  				Eventually(session).Should(Exit(0))
    37  			})
    38  		})
    39  	})
    40  
    41  	When("the environment is not setup correctly", func() {
    42  		It("fails with the appropriate errors", func() {
    43  			helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "set-space-isolation-segment", "space-name", "isolation-seg-name")
    44  		})
    45  
    46  		When("the v3 api version is lower than the minimum version", func() {
    47  			var server *Server
    48  
    49  			BeforeEach(func() {
    50  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion)
    51  			})
    52  
    53  			AfterEach(func() {
    54  				server.Close()
    55  			})
    56  
    57  			It("fails with error message that the minimum version is not met", func() {
    58  				session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)
    59  				Eventually(session).Should(Say("FAILED"))
    60  				Eventually(session.Err).Should(Say(`This command requires CF API version 3\.11\.0 or higher\.`))
    61  				Eventually(session).Should(Exit(1))
    62  			})
    63  		})
    64  	})
    65  
    66  	When("the environment is set up correctly", func() {
    67  		var userName string
    68  
    69  		BeforeEach(func() {
    70  			helpers.LoginCF()
    71  			userName, _ = helpers.GetCredentials()
    72  			helpers.CreateOrg(organizationName)
    73  			helpers.TargetOrg(organizationName)
    74  		})
    75  
    76  		AfterEach(func() {
    77  			helpers.QuickDeleteOrg(organizationName)
    78  		})
    79  
    80  		When("the space does not exist", func() {
    81  			It("fails with space not found message", func() {
    82  				session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)
    83  				Eventually(session).Should(Say(`Updating isolation segment of space %s in org %s as %s\.\.\.`, spaceName, organizationName, userName))
    84  				Eventually(session).Should(Say("FAILED"))
    85  				Eventually(session.Err).Should(Say("Space '%s' not found.", spaceName))
    86  				Eventually(session).Should(Exit(1))
    87  			})
    88  		})
    89  
    90  		When("the space exists", func() {
    91  			BeforeEach(func() {
    92  				helpers.CreateSpace(spaceName)
    93  			})
    94  
    95  			When("the isolation segment does not exist", func() {
    96  				It("fails with isolation segment not found message", func() {
    97  					session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)
    98  					Eventually(session).Should(Say(`Updating isolation segment of space %s in org %s as %s\.\.\.`, spaceName, organizationName, userName))
    99  					Eventually(session).Should(Say("FAILED"))
   100  					Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName))
   101  					Eventually(session).Should(Exit(1))
   102  				})
   103  			})
   104  
   105  			When("the isolation segment exists", func() {
   106  				BeforeEach(func() {
   107  					Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   108  				})
   109  
   110  				When("the isolation segment is entitled to the organization", func() {
   111  					BeforeEach(func() {
   112  						Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0))
   113  					})
   114  
   115  					It("displays OK", func() {
   116  						session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)
   117  						Eventually(session).Should(Say(`Updating isolation segment of space %s in org %s as %s\.\.\.`, spaceName, organizationName, userName))
   118  						Eventually(session).Should(Say("OK"))
   119  						Eventually(session).Should(Say("In order to move running applications to this isolation segment, they must be restarted."))
   120  						Eventually(session).Should(Exit(0))
   121  					})
   122  
   123  					When("the isolation is already set to space", func() {
   124  						BeforeEach(func() {
   125  							Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0))
   126  						})
   127  
   128  						It("displays OK", func() {
   129  							session := helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)
   130  							Eventually(session).Should(Say(`Updating isolation segment of space %s in org %s as %s\.\.\.`, spaceName, organizationName, userName))
   131  							Eventually(session).Should(Say("OK"))
   132  							Eventually(session).Should(Say("In order to move running applications to this isolation segment, they must be restarted."))
   133  							Eventually(session).Should(Exit(0))
   134  						})
   135  					})
   136  				})
   137  			})
   138  		})
   139  	})
   140  })