github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/move_route_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     5  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gbytes"
    10  	. "github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("move route command", func() {
    14  	Context("Help", func() {
    15  		It("appears in cf help -a", func() {
    16  			session := helpers.CF("help", "-a")
    17  
    18  			Eventually(session).Should(Exit(0))
    19  			Expect(session).To(HaveCommandInCategoryWithDescription("move-route", "ROUTES", "Assign a route to a different space"))
    20  		})
    21  
    22  		It("displays the help information", func() {
    23  			session := helpers.CF("move-route", "--help")
    24  			Eventually(session).Should(Say(`NAME:`))
    25  			Eventually(session).Should(Say("move-route - Assign a route to a different space"))
    26  			Eventually(session).Should(Say(`\n`))
    27  
    28  			Eventually(session).Should(Say(`USAGE:`))
    29  			Eventually(session).Should(Say(`Transfers the ownership of a route to a another space:`))
    30  			Eventually(session).Should(Say(`cf move-route DOMAIN \[--hostname HOSTNAME\] \[--path PATH\] -s OTHER_SPACE \[-o OTHER_ORG\]`))
    31  			Eventually(session).Should(Say(`\n`))
    32  
    33  			Eventually(session).Should(Say(`EXAMPLES:`))
    34  			Eventually(session).Should(Say(`cf move-route example.com --hostname myHost --path foo -s TargetSpace -o TargetOrg        # myhost.example.com/foo`))
    35  			Eventually(session).Should(Say(`cf move-route example.com --hostname myHost -s TargetSpace                                # myhost.example.com`))
    36  			Eventually(session).Should(Say(`cf move-route example.com --hostname myHost -s TargetSpace -o TargetOrg                   # myhost.example.com`))
    37  			Eventually(session).Should(Say(`\n`))
    38  
    39  			Eventually(session).Should(Say(`OPTIONS:`))
    40  			Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`))
    41  			Eventually(session).Should(Say(`--path\s+Path for the HTTP route`))
    42  			Eventually(session).Should(Say(`-o\s+The org of the destination app \(Default: targeted org\)`))
    43  			Eventually(session).Should(Say(`-s\s+The space of the destination app \(Default: targeted space\)`))
    44  			Eventually(session).Should(Say(`\n`))
    45  
    46  			Eventually(session).Should(Say(`SEE ALSO:`))
    47  			Eventually(session).Should(Say(`create-route, map-route, routes, unmap-route`))
    48  
    49  			Eventually(session).Should(Exit(0))
    50  		})
    51  	})
    52  
    53  	When("the environment is not setup correctly", func() {
    54  		It("fails with the appropriate errors", func() {
    55  			helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "move-route", "some-domain", "-s SOME_SPACE")
    56  		})
    57  	})
    58  
    59  	When("the environment is set up correctly", func() {
    60  		var (
    61  			userName  string
    62  			orgName   string
    63  			spaceName string
    64  		)
    65  
    66  		BeforeEach(func() {
    67  			helpers.SkipIfVersionLessThan(ccversion.MinVersionHTTP2RoutingV3)
    68  			orgName = helpers.NewOrgName()
    69  			spaceName = helpers.NewSpaceName()
    70  
    71  			helpers.SetupCF(orgName, spaceName)
    72  			userName, _ = helpers.GetCredentials()
    73  		})
    74  
    75  		AfterEach(func() {
    76  			helpers.QuickDeleteOrg(orgName)
    77  		})
    78  
    79  		When("the domain exists", func() {
    80  			var (
    81  				domainName      string
    82  				targetSpaceName string
    83  			)
    84  
    85  			BeforeEach(func() {
    86  				domainName = helpers.NewDomainName()
    87  			})
    88  
    89  			When("the route exists", func() {
    90  				var (
    91  					domain   helpers.Domain
    92  					hostname string
    93  				)
    94  				When("the target space exists in targeted org", func() {
    95  					BeforeEach(func() {
    96  						domain = helpers.NewDomain(orgName, domainName)
    97  						hostname = "panera-bread"
    98  						targetSpaceName = helpers.NewSpaceName()
    99  						helpers.CreateSpace(targetSpaceName)
   100  						domain.CreateShared()
   101  						Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname)).Should(Exit(0))
   102  					})
   103  
   104  					AfterEach(func() {
   105  						domain.DeleteShared()
   106  					})
   107  
   108  					It("transfers the route to the destination space", func() {
   109  						session := helpers.CF("move-route", domainName, "--hostname", hostname, "-s", targetSpaceName)
   110  						Eventually(session).Should(Say(`Move ownership of route %s.%s to space %s as %s`, hostname, domainName, targetSpaceName, userName))
   111  						Eventually(session).Should(Say(`OK`))
   112  						Eventually(session).Should(Exit(0))
   113  					})
   114  				})
   115  
   116  				When("the target organization does not exist", func() {
   117  					var targetOrgName string
   118  					BeforeEach(func() {
   119  						domain = helpers.NewDomain(orgName, domainName)
   120  						hostname = "panera-bread"
   121  						targetSpaceName = helpers.NewSpaceName()
   122  						targetOrgName = helpers.NewOrgName()
   123  						domain.CreateShared()
   124  						Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname)).Should(Exit(0))
   125  					})
   126  
   127  					It("exists with 1 and an error message", func() {
   128  						session := helpers.CF("move-route", domainName, "--hostname", hostname, "-o", targetOrgName, "-s", targetSpaceName)
   129  						Eventually(session).Should(Say("Can not transfer ownership of route:"))
   130  						Eventually(session).Should(Say(`FAILED`))
   131  						Eventually(session).Should(Exit(1))
   132  					})
   133  				})
   134  
   135  				When("the target space exists in another existing org", func() {
   136  					var targetOrgName string
   137  					BeforeEach(func() {
   138  						domain = helpers.NewDomain(orgName, domainName)
   139  						hostname = "menchies-icecream"
   140  						targetOrgName = helpers.NewOrgName()
   141  						targetSpaceName = helpers.NewSpaceName()
   142  						helpers.CreateOrgAndSpace(targetOrgName, targetSpaceName)
   143  						helpers.SetupCF(orgName, spaceName)
   144  						domain.CreateShared()
   145  						Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname)).Should(Exit(0))
   146  					})
   147  
   148  					AfterEach(func() {
   149  						domain.DeleteShared()
   150  					})
   151  
   152  					It("Transfers ownership of the route to the destination space", func() {
   153  						session := helpers.CF("move-route", domainName, "--hostname", hostname, "-o", targetOrgName, "-s", targetSpaceName)
   154  						Eventually(session).Should(Say(`Move ownership of route %s.%s to space %s as %s`, hostname, domainName, targetSpaceName, userName))
   155  						Eventually(session).Should(Say(`OK`))
   156  						Eventually(session).Should(Exit(0))
   157  					})
   158  				})
   159  
   160  				When("the space does not exist", func() {
   161  					var destinationSpaceName string
   162  					BeforeEach(func() {
   163  						domain = helpers.NewDomain(orgName, domainName)
   164  						hostname = "menchies-icecream"
   165  						destinationSpaceName = "doesNotExistSpace"
   166  						domain.CreateShared()
   167  						Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname)).Should(Exit(0))
   168  					})
   169  
   170  					It("exists with 1 with an error", func() {
   171  						session := helpers.CF("move-route", domainName, "--hostname", hostname, "-s", destinationSpaceName)
   172  						Eventually(session).Should(Say("Can not transfer ownership of route:"))
   173  						Eventually(session).Should(Say(`FAILED`))
   174  						Eventually(session).Should(Exit(1))
   175  					})
   176  				})
   177  			})
   178  
   179  			When("the route does not exist", func() {
   180  				var (
   181  					domain   helpers.Domain
   182  					hostname string
   183  				)
   184  
   185  				When("the target space exists", func() {
   186  					BeforeEach(func() {
   187  						domain = helpers.NewDomain(orgName, domainName)
   188  						hostname = "panera-bread"
   189  						targetSpaceName = helpers.NewSpaceName()
   190  						helpers.CreateSpace(targetSpaceName)
   191  						domain.CreateShared()
   192  					})
   193  
   194  					It("exits with 1 with an error message", func() {
   195  						session := helpers.CF("move-route", domainName, "--hostname", hostname, "-s", targetSpaceName)
   196  						Eventually(session).Should(Say("Can not transfer ownership of route:"))
   197  						Eventually(session).Should(Say(`FAILED`))
   198  						Eventually(session).Should(Exit(1))
   199  					})
   200  				})
   201  			})
   202  		})
   203  	})
   204  })