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