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