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