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

     1  package isolated
     2  
     3  import (
     4  	"fmt"
     5  
     6  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     7  	"code.cloudfoundry.org/cli/integration/helpers"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("unmap-route command", func() {
    15  	Context("help", func() {
    16  		It("appears in cf help -a", func() {
    17  			session := helpers.CF("help", "-a")
    18  			Eventually(session).Should(Exit(0))
    19  			Expect(session).To(HaveCommandInCategoryWithDescription("unmap-route", "ROUTES", "Remove a route from an app"))
    20  		})
    21  
    22  		It("Displays command usage to output", func() {
    23  			session := helpers.CF("unmap-route", "--help")
    24  			Eventually(session).Should(Say(`NAME:`))
    25  			Eventually(session).Should(Say(`unmap-route - Remove a route from an app\n`))
    26  			Eventually(session).Should(Say(`\n`))
    27  
    28  			Eventually(session).Should(Say(`USAGE:`))
    29  			Eventually(session).Should(Say(`Unmap an HTTP route:`))
    30  			Eventually(session).Should(Say(`\s+cf unmap-route APP_NAME DOMAIN \[--hostname HOSTNAME\] \[--path PATH\]\n`))
    31  			Eventually(session).Should(Say(`Unmap a TCP route:`))
    32  			Eventually(session).Should(Say(`\s+cf unmap-route APP_NAME DOMAIN --port PORT\n`))
    33  			Eventually(session).Should(Say(`\n`))
    34  
    35  			Eventually(session).Should(Say(`EXAMPLES:`))
    36  			Eventually(session).Should(Say(`cf unmap-route my-app example.com                              # example.com`))
    37  			Eventually(session).Should(Say(`cf unmap-route my-app example.com --hostname myhost            # myhost.example.com`))
    38  			Eventually(session).Should(Say(`cf unmap-route my-app example.com --hostname myhost --path foo # myhost.example.com/foo`))
    39  			Eventually(session).Should(Say(`cf unmap-route my-app example.com --port 5000                  # example.com:5000`))
    40  			Eventually(session).Should(Say(`\n`))
    41  
    42  			Eventually(session).Should(Say(`OPTIONS:`))
    43  			Eventually(session).Should(Say(`--hostname, -n\s+Hostname used to identify the HTTP route`))
    44  			Eventually(session).Should(Say(`--path\s+Path used to identify the HTTP route`))
    45  			Eventually(session).Should(Say(`--port\s+Port used to identify the TCP route`))
    46  			Eventually(session).Should(Say(`\n`))
    47  
    48  			Eventually(session).Should(Say(`SEE ALSO:`))
    49  			Eventually(session).Should(Say(`delete-route, map-route, routes`))
    50  
    51  			Eventually(session).Should(Exit(0))
    52  		})
    53  	})
    54  
    55  	When("the environment is not setup correctly", func() {
    56  		It("fails with the appropriate errors", func() {
    57  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "map-route", "app-name", "domain-name")
    58  		})
    59  	})
    60  
    61  	When("The environment is set up correctly", func() {
    62  		var (
    63  			orgName    string
    64  			spaceName  string
    65  			hostName   string
    66  			path       string
    67  			domainName string
    68  			userName   string
    69  			appName    string
    70  			route      helpers.Route
    71  			tcpRoute   helpers.Route
    72  			port       int
    73  			tcpDomain  helpers.Domain
    74  		)
    75  
    76  		BeforeEach(func() {
    77  			orgName = helpers.NewOrgName()
    78  			spaceName = helpers.NewSpaceName()
    79  			appName = helpers.NewAppName()
    80  			hostName = helpers.NewHostName()
    81  			path = helpers.NewPath()
    82  			helpers.SetupCF(orgName, spaceName)
    83  			userName, _ = helpers.GetCredentials()
    84  			domainName = helpers.DefaultSharedDomain()
    85  
    86  			routerGroupName := helpers.FindOrCreateTCPRouterGroup(4)
    87  			tcpDomain = helpers.NewDomain(orgName, helpers.NewDomainName("TCP-DOMAIN"))
    88  			tcpDomain.CreateWithRouterGroup(routerGroupName)
    89  
    90  			route = helpers.NewRoute(spaceName, domainName, hostName, path)
    91  			route.V7Create()
    92  
    93  			helpers.WithHelloWorldApp(func(dir string) {
    94  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "push", appName)
    95  				Eventually(session).Should(Exit(0))
    96  			})
    97  		})
    98  
    99  		AfterEach(func() {
   100  			route.Delete()
   101  		})
   102  
   103  		When("the route exists and is mapped to the app", func() {
   104  			When("it's an http route", func() {
   105  				BeforeEach(func() {
   106  					session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
   107  					Eventually(session).Should(Exit(0))
   108  				})
   109  
   110  				It("unmaps the route from the app", func() {
   111  					session := helpers.CF("unmap-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
   112  
   113  					Eventually(session).Should(Say(`Removing route %s.%s%s from app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName))
   114  					Eventually(session).Should(Say(`OK`))
   115  					Eventually(session).Should(Exit(0))
   116  				})
   117  			})
   118  			When("it's a TCP route", func() {
   119  				BeforeEach(func() {
   120  					port = 1024
   121  					tcpRoute = helpers.NewTCPRoute(spaceName, tcpDomain.Name, port)
   122  					session := helpers.CF("map-route", appName, tcpDomain.Name, "--port", fmt.Sprintf("%d", tcpRoute.Port))
   123  					Eventually(session).Should(Exit(0))
   124  				})
   125  
   126  				It("unmaps the route from the app", func() {
   127  					session := helpers.CF("unmap-route", appName, tcpDomain.Name, "--port", fmt.Sprintf("%d", tcpRoute.Port))
   128  
   129  					Eventually(session).Should(Say(`Removing route %s:%d from app %s in org %s / space %s as %s\.\.\.`, tcpDomain.Name, tcpRoute.Port, appName, orgName, spaceName, userName))
   130  					Eventually(session).Should(Say(`OK`))
   131  					Eventually(session).Should(Exit(0))
   132  				})
   133  			})
   134  		})
   135  
   136  		When("the route exists but is not mapped to the app", func() {
   137  			It("prints a message and exits with status 0", func() {
   138  				session := helpers.CF("unmap-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
   139  
   140  				Eventually(session).Should(Say("Route to be unmapped is not currently mapped to the application."))
   141  				Eventually(session).Should(Say(`OK`))
   142  				Eventually(session).Should(Exit(0))
   143  			})
   144  		})
   145  
   146  		When("the route doesn't exist", func() {
   147  			It("fails with a helpful message", func() {
   148  				session := helpers.CF("unmap-route", appName, domainName, "--hostname", "test", "--path", "does-not-exist")
   149  
   150  				Eventually(session.Err).Should(Say(`Route with host 'test', domain '%s', and path '/does-not-exist' not found.`, domainName))
   151  				Eventually(session).Should(Say(`FAILED`))
   152  				Eventually(session).Should(Exit(1))
   153  			})
   154  		})
   155  	})
   156  })