github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/map_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  
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gbytes"
    12  	. "github.com/onsi/gomega/gexec"
    13  )
    14  
    15  var _ = Describe("map-route command", func() {
    16  	Context("help", func() {
    17  		It("appears in cf help -a", func() {
    18  			session := helpers.CF("help", "-a")
    19  			Eventually(session).Should(Exit(0))
    20  			Expect(session).To(HaveCommandInCategoryWithDescription("map-route", "ROUTES", "Map a route to an app"))
    21  		})
    22  
    23  		It("displays command usage to output", func() {
    24  			session := helpers.CF("map-route", "--help")
    25  			Eventually(session).Should(Say(`NAME:`))
    26  			Eventually(session).Should(Say(`map-route - Map a route to an app\n`))
    27  			Eventually(session).Should(Say(`\n`))
    28  
    29  			Eventually(session).Should(Say(`USAGE:`))
    30  			Eventually(session).Should(Say(`Map an HTTP route:\n`))
    31  			Eventually(session).Should(Say(`cf map-route APP_NAME DOMAIN \[--hostname HOSTNAME\] \[--path PATH\]\n`))
    32  			Eventually(session).Should(Say(`Map a TCP route:\n`))
    33  			Eventually(session).Should(Say(`cf map-route APP_NAME DOMAIN \[--port PORT]\n`))
    34  			Eventually(session).Should(Say(`\n`))
    35  
    36  			Eventually(session).Should(Say(`EXAMPLES:`))
    37  			Eventually(session).Should(Say(`cf map-route my-app example.com                              # example.com`))
    38  			Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost            # myhost.example.com`))
    39  			Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost --path foo # myhost.example.com/foo`))
    40  			Eventually(session).Should(Say(`cf map-route my-app example.com --port 5000                  # example.com:5000`))
    41  			Eventually(session).Should(Say(`\n`))
    42  
    43  			Eventually(session).Should(Say(`OPTIONS:`))
    44  			Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`))
    45  			Eventually(session).Should(Say(`--path\s+Path for the HTTP route`))
    46  			Eventually(session).Should(Say(`--port\s+Port for the TCP route \(default: random port\)`))
    47  			Eventually(session).Should(Say(`\n`))
    48  
    49  			Eventually(session).Should(Say(`SEE ALSO:`))
    50  			Eventually(session).Should(Say(`create-route, routes, unmap-route`))
    51  
    52  			Eventually(session).Should(Exit(0))
    53  		})
    54  	})
    55  
    56  	When("the environment is not setup correctly", func() {
    57  		It("fails with the appropriate errors", func() {
    58  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "map-route", "app-name", "domain-name")
    59  		})
    60  	})
    61  
    62  	When("the environment is set up correctly", func() {
    63  		var (
    64  			orgName    string
    65  			spaceName  string
    66  			domainName string
    67  			hostName   string
    68  			path       string
    69  			userName   string
    70  			appName    string
    71  		)
    72  
    73  		BeforeEach(func() {
    74  			appName = helpers.NewAppName()
    75  			hostName = helpers.NewHostName()
    76  			path = helpers.NewPath()
    77  			orgName = helpers.NewOrgName()
    78  			spaceName = helpers.NewSpaceName()
    79  			helpers.SetupCF(orgName, spaceName)
    80  			userName, _ = helpers.GetCredentials()
    81  
    82  			helpers.WithHelloWorldApp(func(dir string) {
    83  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "push", appName)
    84  				Eventually(session).Should(Exit(0))
    85  			})
    86  		})
    87  
    88  		When("the http route already exists", func() {
    89  			var (
    90  				route helpers.Route
    91  			)
    92  
    93  			BeforeEach(func() {
    94  				domainName = helpers.DefaultSharedDomain()
    95  				route = helpers.NewRoute(spaceName, domainName, hostName, path)
    96  				route.V7Create()
    97  			})
    98  
    99  			AfterEach(func() {
   100  				route.Delete()
   101  			})
   102  			When("route is already mapped to app", func() {
   103  				BeforeEach(func() {
   104  					session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
   105  					Eventually(session).Should(Exit(0))
   106  				})
   107  				It("exits 0 with helpful message saying that the route is already mapped to the app", func() {
   108  					session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
   109  
   110  					Eventually(session).Should(Say(`Mapping route %s.%s%s to app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName))
   111  					Eventually(session).Should(Say(`App '%s' is already mapped to route '%s.%s%s'\.`, appName, hostName, domainName, path))
   112  					Eventually(session).Should(Say(`OK`))
   113  					Eventually(session).Should(Exit(0))
   114  
   115  				})
   116  			})
   117  			When("route is not yet mapped to the app", func() {
   118  				It("maps the route to an app", func() {
   119  					session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
   120  
   121  					Eventually(session).Should(Say(`Mapping route %s.%s%s to app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName))
   122  					Eventually(session).Should(Say(`OK`))
   123  					Eventually(session).Should(Exit(0))
   124  				})
   125  			})
   126  		})
   127  
   128  		When("the tcp route already exists", func() {
   129  			var (
   130  				domain      helpers.Domain
   131  				routerGroup helpers.RouterGroup
   132  				route       helpers.Route
   133  			)
   134  
   135  			BeforeEach(func() {
   136  				domainName = helpers.NewDomainName()
   137  				domain = helpers.NewDomain("", domainName)
   138  				routerGroup = helpers.NewRouterGroup(
   139  					helpers.NewRouterGroupName(),
   140  					"1024-2048",
   141  				)
   142  
   143  				routerGroup.Create()
   144  				domain.CreateWithRouterGroup(routerGroup.Name)
   145  				route = helpers.NewTCPRoute(spaceName, domainName, 1082)
   146  			})
   147  
   148  			AfterEach(func() {
   149  				domain.DeleteShared()
   150  				routerGroup.Delete()
   151  			})
   152  
   153  			When("route is already mapped to app", func() {
   154  				BeforeEach(func() {
   155  					session := helpers.CF("map-route", appName, domainName, "--port", fmt.Sprintf("%d", route.Port))
   156  					Eventually(session).Should(Exit(0))
   157  				})
   158  				It("exits 0 with helpful message saying that the route is already mapped to the app", func() {
   159  					session := helpers.CF("map-route", appName, domainName, "--port", fmt.Sprintf("%d", route.Port))
   160  
   161  					Eventually(session).Should(Say(`Mapping route %s:%d to app %s in org %s / space %s as %s\.\.\.`, domainName, route.Port, appName, orgName, spaceName, userName))
   162  					Eventually(session).Should(Say(`App '%s' is already mapped to route '%s:%d'\.`, appName, domainName, route.Port))
   163  					Eventually(session).Should(Say(`OK`))
   164  					Eventually(session).Should(Exit(0))
   165  				})
   166  			})
   167  
   168  			When("route is not yet mapped to the app", func() {
   169  				It("maps the route to an app", func() {
   170  					session := helpers.CF("map-route", appName, domainName, "--port", fmt.Sprintf("%d", route.Port))
   171  
   172  					Eventually(session).Should(Say(`Mapping route %s:%d to app %s in org %s / space %s as %s\.\.\.`, domainName, route.Port, appName, orgName, spaceName, userName))
   173  					Eventually(session).Should(Say(`OK`))
   174  					Eventually(session).Should(Exit(0))
   175  				})
   176  			})
   177  
   178  			When("port is not specified", func() {
   179  				It("creates a new route with a random port and maps it to the app", func() {
   180  					session := helpers.CF("map-route", appName, domainName)
   181  
   182  					Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName))
   183  					Eventually(session).Should(Say(`OK`))
   184  					Eventually(session).Should(Say(`Mapping route %s:[0-9]+ to app %s in org %s / space %s as %s\.\.\.`, domainName, appName, orgName, spaceName, userName))
   185  					Eventually(session).Should(Say(`OK`))
   186  					Eventually(session).Should(Exit(0))
   187  				})
   188  			})
   189  		})
   190  
   191  		When("the route does *not* exist", func() {
   192  			When("it is an HTTP domain", func() {
   193  				BeforeEach(func() {
   194  					domainName = helpers.DefaultSharedDomain()
   195  				})
   196  
   197  				It("creates the route and maps it to an app", func() {
   198  					session := helpers.CF("map-route", appName, domainName, "--hostname", hostName, "--path", path)
   199  					Eventually(session).Should(Say(`Creating route %s.%s%s for org %s / space %s as %s\.\.\.`, hostName, domainName, path, orgName, spaceName, userName))
   200  					Eventually(session).Should(Say(`OK`))
   201  					Eventually(session).Should(Say(`Mapping route %s.%s%s to app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName))
   202  					Eventually(session).Should(Say(`OK`))
   203  					Eventually(session).Should(Exit(0))
   204  				})
   205  			})
   206  
   207  			When("it is an TCP domain", func() {
   208  				var (
   209  					domain      helpers.Domain
   210  					routerGroup helpers.RouterGroup
   211  				)
   212  
   213  				BeforeEach(func() {
   214  					domainName = helpers.NewDomainName()
   215  					domain = helpers.NewDomain("", domainName)
   216  					routerGroup = helpers.NewRouterGroup(
   217  						helpers.NewRouterGroupName(),
   218  						"1024-2048",
   219  					)
   220  
   221  					routerGroup.Create()
   222  					domain.CreateWithRouterGroup(routerGroup.Name)
   223  				})
   224  
   225  				AfterEach(func() {
   226  					domain.DeleteShared()
   227  					routerGroup.Delete()
   228  				})
   229  
   230  				When("a port is provided", func() {
   231  					It("creates the route and maps it to an app", func() {
   232  						session := helpers.CF("map-route", appName, domainName, "--port", "1052")
   233  						Eventually(session).Should(Say(`Creating route %s:%s for org %s / space %s as %s\.\.\.`, domainName, "1052", orgName, spaceName, userName))
   234  						Eventually(session).Should(Say(`OK`))
   235  						Eventually(session).Should(Say(`Mapping route %s:%s to app %s in org %s / space %s as %s\.\.\.`, domainName, "1052", appName, orgName, spaceName, userName))
   236  						Eventually(session).Should(Say(`OK`))
   237  						Eventually(session).Should(Exit(0))
   238  					})
   239  				})
   240  
   241  				When("a port is not provided", func() {
   242  					It("creates the route and maps it to an app", func() {
   243  						session := helpers.CF("map-route", appName, domainName)
   244  						Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName))
   245  						Eventually(session).Should(Say(`OK`))
   246  						Eventually(session).Should(Say(`Mapping route %s:[0-9]+ to app %s in org %s / space %s as %s\.\.\.`, domainName, appName, orgName, spaceName, userName))
   247  						Eventually(session).Should(Say(`OK`))
   248  						Eventually(session).Should(Exit(0))
   249  					})
   250  				})
   251  			})
   252  		})
   253  	})
   254  })