github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/rename_space_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     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  )
    11  
    12  var _ = Describe("rename-space command", func() {
    13  	var (
    14  		orgName      string
    15  		spaceName    string
    16  		spaceNameNew string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		orgName = helpers.NewOrgName()
    21  		spaceName = helpers.NewSpaceName()
    22  		spaceNameNew = helpers.NewSpaceName()
    23  	})
    24  
    25  	Describe("help", func() {
    26  		When("--help flag is set", func() {
    27  			It("appears in cf help -a", func() {
    28  				session := helpers.CF("help", "-a")
    29  				Eventually(session).Should(Exit(0))
    30  				Expect(session).To(HaveCommandInCategoryWithDescription("rename-space", "SPACES", "Rename a space"))
    31  			})
    32  
    33  			It("Displays command usage to output", func() {
    34  				session := helpers.CF("rename-space", "--help")
    35  				Eventually(session).Should(Say("NAME:"))
    36  				Eventually(session).Should(Say("rename-space - Rename a space"))
    37  				Eventually(session).Should(Say("USAGE:"))
    38  				Eventually(session).Should(Say(`cf rename-space SPACE NEW_SPACE_NAME`))
    39  				Eventually(session).Should(Say("SEE ALSO:"))
    40  				Eventually(session).Should(Say("space, space-quotas, space-users, spaces, target"))
    41  				Eventually(session).Should(Exit(0))
    42  			})
    43  		})
    44  	})
    45  
    46  	When("the space name is not provided", func() {
    47  		It("tells the user that the space name is required, prints help text, and exits 1", func() {
    48  			session := helpers.CF("rename-space")
    49  
    50  			Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SPACE` and `NEW_SPACE_NAME` were not provided"))
    51  			Eventually(session).Should(Say("NAME:"))
    52  			Eventually(session).Should(Exit(1))
    53  		})
    54  	})
    55  
    56  	When("the new space name is not provided", func() {
    57  		It("tells the user that the space name is required, prints help text, and exits 1", func() {
    58  			session := helpers.CF("rename-space", "space")
    59  
    60  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `NEW_SPACE_NAME` was not provided"))
    61  			Eventually(session).Should(Say("NAME:"))
    62  			Eventually(session).Should(Exit(1))
    63  		})
    64  	})
    65  
    66  	When("the environment is not setup correctly", func() {
    67  		It("fails with the appropriate errors", func() {
    68  			helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "rename-space", spaceName, spaceNameNew)
    69  		})
    70  	})
    71  
    72  	When("the environment is set up correctly", func() {
    73  		BeforeEach(func() {
    74  			helpers.SetupCF(orgName, spaceName)
    75  		})
    76  
    77  		AfterEach(func() {
    78  			helpers.QuickDeleteOrg(orgName)
    79  		})
    80  
    81  		When("space does not exist", func() {
    82  			It("tells the user that the space does not exist, prints help text, and exits 1", func() {
    83  				session := helpers.CF("rename-space", "not-a-space", spaceNameNew)
    84  
    85  				Eventually(session.Err).Should(Say("Space 'not-a-space' not found."))
    86  				Eventually(session).Should(Exit(1))
    87  			})
    88  		})
    89  
    90  		When("the space does exist", func() {
    91  			It("renames the space in the targeted org", func() {
    92  				session := helpers.CF("rename-space", spaceName, spaceNameNew)
    93  				userName, _ := helpers.GetCredentials()
    94  				Eventually(session).Should(Say("Renaming space %s to %s as %s...", spaceName, spaceNameNew, userName))
    95  				Eventually(session).Should(Say("OK"))
    96  				Eventually(session).Should(Exit(0))
    97  
    98  				session = helpers.CF("space", spaceNameNew)
    99  				Eventually(session).Should(Say(`name:\s+%s`, spaceNameNew))
   100  				Eventually(session).Should(Exit(0))
   101  			})
   102  		})
   103  	})
   104  })