github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/rename_org_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-org command", func() {
    13  	var (
    14  		orgName    string
    15  		orgNameNew string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		orgName = helpers.NewOrgName()
    20  		orgNameNew = helpers.NewOrgName()
    21  	})
    22  
    23  	Describe("help", func() {
    24  		When("--help flag is set", func() {
    25  			It("appears in cf help -a", func() {
    26  				session := helpers.CF("help", "-a")
    27  				Eventually(session).Should(Exit(0))
    28  				Expect(session).To(HaveCommandInCategoryWithDescription("rename-org", "ORGS", "Rename an org"))
    29  			})
    30  
    31  			It("Displays command usage to output", func() {
    32  				session := helpers.CF("rename-org", "--help")
    33  				Eventually(session).Should(Say("NAME:"))
    34  				Eventually(session).Should(Say("rename-org - Rename an org"))
    35  				Eventually(session).Should(Say("USAGE:"))
    36  				Eventually(session).Should(Say(`cf rename-org ORG NEW_ORG_NAME`))
    37  				Eventually(session).Should(Say("SEE ALSO:"))
    38  				Eventually(session).Should(Say("orgs, quotas, set-org-role"))
    39  				Eventually(session).Should(Exit(0))
    40  			})
    41  		})
    42  	})
    43  
    44  	When("the org name is not provided", func() {
    45  		It("tells the user that the org name is required, prints help text, and exits 1", func() {
    46  			session := helpers.CF("rename-org")
    47  
    48  			Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `ORG` and `NEW_ORG_NAME` were not provided"))
    49  			Eventually(session).Should(Say("NAME:"))
    50  			Eventually(session).Should(Exit(1))
    51  		})
    52  	})
    53  
    54  	When("the new org name is not provided", func() {
    55  		It("tells the user that the org name is required, prints help text, and exits 1", func() {
    56  			session := helpers.CF("rename-org", "org")
    57  
    58  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `NEW_ORG_NAME` was not provided"))
    59  			Eventually(session).Should(Say("NAME:"))
    60  			Eventually(session).Should(Exit(1))
    61  		})
    62  	})
    63  
    64  	When("the environment is not setup correctly", func() {
    65  		It("fails with the appropriate errors", func() {
    66  			helpers.CheckEnvironmentTargetedCorrectly(false, false, "", "rename-org", orgName, orgNameNew)
    67  		})
    68  	})
    69  
    70  	When("the environment is set up correctly", func() {
    71  		BeforeEach(func() {
    72  			helpers.LoginCF()
    73  		})
    74  
    75  		When("org does not exist", func() {
    76  			It("tells the user that the org does not exist, prints help text, and exits 1", func() {
    77  				session := helpers.CF("rename-org", "not-an-org", orgNameNew)
    78  
    79  				Eventually(session.Err).Should(Say("Organization 'not-an-org' not found."))
    80  				Eventually(session).Should(Exit(1))
    81  			})
    82  		})
    83  
    84  		When("the org does exist", func() {
    85  			BeforeEach(func() {
    86  				helpers.CreateOrg(orgName)
    87  			})
    88  
    89  			AfterEach(func() {
    90  				helpers.QuickDeleteOrg(orgNameNew)
    91  			})
    92  
    93  			It("renames the org", func() {
    94  				session := helpers.CF("rename-org", orgName, orgNameNew)
    95  				userName, _ := helpers.GetCredentials()
    96  				Eventually(session).Should(Say("Renaming org %s to %s as %s...", orgName, orgNameNew, userName))
    97  				Eventually(session).Should(Say("OK"))
    98  				Eventually(session).Should(Exit(0))
    99  
   100  				session = helpers.CF("org", orgNameNew)
   101  				Eventually(session).Should(Say(`name:\s+%s`, orgNameNew))
   102  				Eventually(session).Should(Exit(0))
   103  			})
   104  
   105  			When("the new name is already taken", func() {
   106  				BeforeEach(func() {
   107  					helpers.CreateOrg(orgNameNew)
   108  				})
   109  
   110  				It("fails to rename the org", func() {
   111  					session := helpers.CF("rename-org", orgName, orgNameNew)
   112  					userName, _ := helpers.GetCredentials()
   113  					Eventually(session).Should(Say("Renaming org %s to %s as %s...", orgName, orgNameNew, userName))
   114  					Eventually(session.Err).Should(Say(`Organization name '%s' is already taken\.`, orgNameNew))
   115  					Eventually(session).Should(Say("FAILED"))
   116  					Eventually(session).Should(Exit(1))
   117  				})
   118  			})
   119  		})
   120  	})
   121  })