github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/reset_space_isolation_segment_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("reset-space-isolation-segment command", func() {
    12  	var organizationName string
    13  	var spaceName string
    14  
    15  	BeforeEach(func() {
    16  		organizationName = helpers.NewOrgName()
    17  		spaceName = helpers.NewSpaceName()
    18  	})
    19  
    20  	Describe("help", func() {
    21  		When("--help flag is set", func() {
    22  			It("Displays command usage to output", func() {
    23  				session := helpers.CF("reset-space-isolation-segment", "--help")
    24  				Eventually(session).Should(Say("NAME:"))
    25  				Eventually(session).Should(Say("reset-space-isolation-segment - Reset the space's isolation segment to the org default"))
    26  				Eventually(session).Should(Say("USAGE:"))
    27  				Eventually(session).Should(Say("cf reset-space-isolation-segment SPACE_NAME"))
    28  				Eventually(session).Should(Say("SEE ALSO:"))
    29  				Eventually(session).Should(Say("org, restart, space"))
    30  				Eventually(session).Should(Exit(0))
    31  			})
    32  		})
    33  	})
    34  
    35  	When("the environment is not setup correctly", func() {
    36  		When("no API endpoint is set", func() {
    37  			BeforeEach(func() {
    38  				helpers.UnsetAPI()
    39  			})
    40  
    41  			It("fails with no API endpoint set message", func() {
    42  				session := helpers.CF("reset-space-isolation-segment", spaceName)
    43  				Eventually(session).Should(Say("FAILED"))
    44  				Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint."))
    45  				Eventually(session).Should(Exit(1))
    46  			})
    47  		})
    48  
    49  		When("not logged in", func() {
    50  			BeforeEach(func() {
    51  				helpers.LogoutCF()
    52  			})
    53  
    54  			It("fails with not logged in message", func() {
    55  				session := helpers.CF("reset-space-isolation-segment", spaceName)
    56  				Eventually(session).Should(Say("FAILED"))
    57  				Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' or 'cf login --sso' to log in."))
    58  				Eventually(session).Should(Exit(1))
    59  			})
    60  		})
    61  
    62  		When("there is no org set", func() {
    63  			BeforeEach(func() {
    64  				helpers.LoginCF()
    65  			})
    66  
    67  			It("fails with no targeted org error message", func() {
    68  				session := helpers.CF("reset-space-isolation-segment", spaceName)
    69  				Eventually(session).Should(Say("FAILED"))
    70  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org."))
    71  				Eventually(session).Should(Exit(1))
    72  			})
    73  		})
    74  	})
    75  
    76  	When("the environment is set up correctly", func() {
    77  		var userName string
    78  
    79  		BeforeEach(func() {
    80  			helpers.LoginCF()
    81  			userName, _ = helpers.GetCredentials()
    82  			helpers.CreateOrg(organizationName)
    83  			helpers.TargetOrg(organizationName)
    84  		})
    85  
    86  		AfterEach(func() {
    87  			helpers.QuickDeleteOrg(organizationName)
    88  		})
    89  
    90  		When("the space does not exist", func() {
    91  			It("fails with space not found message", func() {
    92  				session := helpers.CF("reset-space-isolation-segment", spaceName)
    93  				Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName))
    94  				Eventually(session).Should(Say("FAILED"))
    95  				Eventually(session.Err).Should(Say("Space '%s' not found.", spaceName))
    96  				Eventually(session).Should(Exit(1))
    97  			})
    98  		})
    99  
   100  		When("the space exists", func() {
   101  			BeforeEach(func() {
   102  				helpers.CreateSpace(spaceName)
   103  				isolationSegmentName := helpers.NewIsolationSegmentName()
   104  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   105  				Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0))
   106  				Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0))
   107  			})
   108  
   109  			When("there is no default org isolation segment", func() {
   110  				It("unsets the space isolation segment", func() {
   111  					session := helpers.CF("reset-space-isolation-segment", spaceName)
   112  					Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName))
   113  
   114  					Eventually(session).Should(Say("OK"))
   115  					Eventually(session).Should(Say("TIP: Restart applications in this space to relocate them to the platform default."))
   116  					Eventually(session).Should(Exit(0))
   117  
   118  					session = helpers.CF("space", spaceName)
   119  					Consistently(session).ShouldNot(Say("isolation segment:/s+"))
   120  					Eventually(session).Should(Exit(0))
   121  				})
   122  			})
   123  
   124  			When("there is a default org isolation segment", func() {
   125  				var orgIsolationSegmentName string
   126  
   127  				BeforeEach(func() {
   128  					orgIsolationSegmentName = helpers.NewIsolationSegmentName()
   129  					Eventually(helpers.CF("create-isolation-segment", orgIsolationSegmentName)).Should(Exit(0))
   130  					Eventually(helpers.CF("enable-org-isolation", organizationName, orgIsolationSegmentName)).Should(Exit(0))
   131  					Eventually(helpers.CF("set-org-default-isolation-segment", organizationName, orgIsolationSegmentName)).Should(Exit(0))
   132  				})
   133  
   134  				It("resets the space isolation segment to the default org isolation segment", func() {
   135  					session := helpers.CF("reset-space-isolation-segment", spaceName)
   136  					Eventually(session).Should(Say("Resetting isolation segment assignment of space %s in org %s as %s...", spaceName, organizationName, userName))
   137  
   138  					Eventually(session).Should(Say("OK"))
   139  					Eventually(session).Should(Say("TIP: Restart applications in this space to relocate them to this organization's default isolation segment."))
   140  					Eventually(session).Should(Exit(0))
   141  
   142  					session = helpers.CF("space", spaceName)
   143  					Eventually(session).Should(Say(`isolation segment:\s+%s`, orgIsolationSegmentName))
   144  					Eventually(session).Should(Exit(0))
   145  				})
   146  			})
   147  		})
   148  	})
   149  })