github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/update_destination_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("update destination command", func() {
    14  	Context("Heltp", 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("update-destination", "ROUTES", "Updates the destination protocol for a route"))
    20  		})
    21  
    22  		It("displays the help information", func() {
    23  			session := helpers.CF("update-destination", "--help")
    24  			Eventually(session).Should(Say(`NAME:`))
    25  			Eventually(session).Should(Say(`update-destination - Updates the destination protocol for a route`))
    26  			Eventually(session).Should(Say(`\n`))
    27  
    28  			Eventually(session).Should(Say(`USAGE:`))
    29  			Eventually(session).Should(Say(`Edit an existing HTTP route`))
    30  			Eventually(session).Should(Say(`cf update-destination APP_NAME DOMAIN \[--hostname HOSTNAME\] \[--app-protocol PROTOCOL\] \[--path PATH\]\n`))
    31  			Eventually(session).Should(Say(`\n`))
    32  
    33  			Eventually(session).Should(Say(`EXAMPLES:`))
    34  			Eventually(session).Should(Say(`cf update-destination my-app example.com --hostname myhost --app-protocol http2                   # myhost.example.com`))
    35  			Eventually(session).Should(Say(`cf update destination my-app example.com --hostname myhost --path foo --app-protocol http2        # myhost.example.com/foo`))
    36  			Eventually(session).Should(Say(`\n`))
    37  
    38  			Eventually(session).Should(Say(`OPTIONS:`))
    39  			Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`))
    40  			Eventually(session).Should(Say(`--app-protocol\s+New Protocol for the route destination \(http1 or http2\). Only applied to HTTP routes`))
    41  			Eventually(session).Should(Say(`--path\s+Path for the HTTP route`))
    42  			Eventually(session).Should(Say(`\n`))
    43  
    44  			Eventually(session).Should(Say(`SEE ALSO:`))
    45  			Eventually(session).Should(Say(`create-route, map-route, routes, unmap-route`))
    46  
    47  			Eventually(session).Should(Exit(0))
    48  		})
    49  	})
    50  
    51  	When("the environment is not setup correctly", func() {
    52  		It("fails with the appropriate errors", func() {
    53  			helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "update-destination", "app-name", "some-domain")
    54  		})
    55  	})
    56  
    57  	When("the environment is set up correctly", func() {
    58  		var (
    59  			userName  string
    60  			orgName   string
    61  			spaceName string
    62  		)
    63  
    64  		BeforeEach(func() {
    65  			helpers.SkipIfVersionLessThan(ccversion.MinVersionHTTP2RoutingV3)
    66  			orgName = helpers.NewOrgName()
    67  			spaceName = helpers.NewSpaceName()
    68  
    69  			helpers.SetupCF(orgName, spaceName)
    70  			userName, _ = helpers.GetCredentials()
    71  		})
    72  
    73  		AfterEach(func() {
    74  			helpers.QuickDeleteOrg(orgName)
    75  		})
    76  
    77  		When("the domain exists", func() {
    78  			var (
    79  				domainName string
    80  			)
    81  
    82  			BeforeEach(func() {
    83  				domainName = helpers.NewDomainName()
    84  			})
    85  
    86  			When("the route exists", func() {
    87  				var (
    88  					domain   helpers.Domain
    89  					appName  string
    90  					hostname string
    91  				)
    92  
    93  				When("it's an HTTP/1 route", func() {
    94  					BeforeEach(func() {
    95  						domain = helpers.NewDomain(orgName, domainName)
    96  						hostname = "key-lime-pie"
    97  						appName = "killer"
    98  						domain.CreatePrivate()
    99  						Eventually(helpers.CF("create-app", appName)).Should(Exit(0))
   100  						Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname)).Should(Exit(0))
   101  						Eventually(helpers.CF("map-route", appName, domain.Name, "--hostname", hostname)).Should(Exit(0))
   102  					})
   103  
   104  					AfterEach(func() {
   105  						domain.Delete()
   106  					})
   107  
   108  					It("updates the destination protocol to http2 ", func() {
   109  						session := helpers.CF("update-destination", appName, domainName, "--hostname", hostname, "--app-protocol", "http2")
   110  						Eventually(session).Should(Say(`Updating destination protocol from %s to %s for route %s.%s in org %s / space %s as %s...`, "http1", "http2", hostname, domainName, orgName, spaceName, userName))
   111  						Eventually(session).Should(Say(`OK`))
   112  						Eventually(session).Should(Exit(0))
   113  					})
   114  				})
   115  
   116  				When("it's an HTTP/2 route", func() {
   117  					BeforeEach(func() {
   118  						domain = helpers.NewDomain(orgName, domainName)
   119  						hostname = "key-lime-pie"
   120  						appName = "killer2"
   121  						domain.CreatePrivate()
   122  						Eventually(helpers.CF("create-app", appName)).Should(Exit(0))
   123  						Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname)).Should(Exit(0))
   124  						Eventually(helpers.CF("map-route", appName, domain.Name, "--hostname", hostname, "--app-protocol", "http2")).Should(Exit(0))
   125  					})
   126  
   127  					AfterEach(func() {
   128  						domain.Delete()
   129  					})
   130  
   131  					It("updates the destination protocol to http1 ", func() {
   132  						session := helpers.CF("update-destination", appName, domainName, "--hostname", hostname, "--app-protocol", "http1")
   133  						Eventually(session).Should(Say(`Updating destination protocol from %s to %s for route %s.%s in org %s / space %s as %s...`, "http2", "http1", hostname, domainName, orgName, spaceName, userName))
   134  						Eventually(session).Should(Say(`OK`))
   135  						Eventually(session).Should(Exit(0))
   136  					})
   137  
   138  					It("does nothing when the app-protocol is the same", func() {
   139  						session := helpers.CF("update-destination", appName, domainName, "--hostname", hostname, "--app-protocol", "http2")
   140  						Eventually(session).Should(Say(`App '%s' is already using '%s'\. Nothing has been updated`, appName, "http2"))
   141  						Eventually(session).Should(Say(`OK`))
   142  						Eventually(session).Should(Exit(0))
   143  					})
   144  
   145  					It("sets the destination protocol to 'http1' when the app-protocol is not provided", func() {
   146  						session := helpers.CF("update-destination", appName, domainName, "--hostname", hostname)
   147  						Eventually(session).Should(Say(`Updating destination protocol from %s to %s for route %s.%s in org %s / space %s as %s...`, "http2", "http1", hostname, domainName, orgName, spaceName, userName))
   148  						Eventually(session).Should(Say(`OK`))
   149  						Eventually(session).Should(Exit(0))
   150  					})
   151  				})
   152  			})
   153  		})
   154  	})
   155  })