github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/check_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("check-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("check-route", "ROUTES", "Perform a check to determine whether a route currently exists or not"))
    20  		})
    21  
    22  		It("displays the help information", func() {
    23  			session := helpers.CF("check-route", "--help")
    24  			Eventually(session).Should(Say(`NAME:`))
    25  			Eventually(session).Should(Say(`check-route - Perform a check to determine whether a route currently exists or not\n`))
    26  			Eventually(session).Should(Say(`\n`))
    27  
    28  			Eventually(session).Should(Say(`USAGE:`))
    29  			Eventually(session).Should(Say(`Check an HTTP route:`))
    30  			Eventually(session).Should(Say(`cf check-route DOMAIN \[--hostname HOSTNAME\] \[--path PATH\]\n`))
    31  			Eventually(session).Should(Say(`Check a TCP route:`))
    32  			Eventually(session).Should(Say(`cf check-route DOMAIN --port PORT\n`))
    33  			Eventually(session).Should(Say(`\n`))
    34  
    35  			Eventually(session).Should(Say(`EXAMPLES:`))
    36  			Eventually(session).Should(Say(`cf check-route example.com                      # example.com`))
    37  			Eventually(session).Should(Say(`cf check-route example.com -n myhost --path foo # myhost.example.com/foo`))
    38  			Eventually(session).Should(Say(`cf check-route example.com --path foo           # example.com/foo`))
    39  			Eventually(session).Should(Say(`cf check-route 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(`create-route, delete-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, false, ReadOnlyOrg, "check-route", "some-domain")
    58  		})
    59  	})
    60  
    61  	When("the environment is set up correctly", func() {
    62  		var (
    63  			orgName   string
    64  			spaceName string
    65  			port      int
    66  			tcpDomain helpers.Domain
    67  		)
    68  
    69  		BeforeEach(func() {
    70  			orgName = helpers.NewOrgName()
    71  			spaceName = helpers.NewSpaceName()
    72  
    73  			helpers.SetupCF(orgName, spaceName)
    74  		})
    75  
    76  		AfterEach(func() {
    77  			helpers.QuickDeleteOrg(orgName)
    78  		})
    79  
    80  		When("the domain exists", func() {
    81  			var (
    82  				domainName 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  
    95  				When("it's an HTTP route", func() {
    96  					BeforeEach(func() {
    97  						domain = helpers.NewDomain(orgName, domainName)
    98  						hostname = "key-lime-pie"
    99  						domain.CreatePrivate()
   100  						Eventually(helpers.CF("create-route", domainName, "--hostname", hostname)).Should(Exit(0))
   101  					})
   102  
   103  					AfterEach(func() {
   104  						domain.Delete()
   105  					})
   106  
   107  					It("tells the user the route exists and exits without failing", func() {
   108  						session := helpers.CF("check-route", domainName, "--hostname", hostname)
   109  						Eventually(session).Should(Say(`Checking for route\.\.\.`))
   110  						Eventually(session).Should(Say(`Route '%s\.%s' does exist\.`, hostname, domainName))
   111  						Eventually(session).Should(Say(`OK`))
   112  						Eventually(session).Should(Exit(0))
   113  					})
   114  				})
   115  
   116  				When("it's a TCP route", func() {
   117  					var (
   118  						routerGroup helpers.RouterGroup
   119  					)
   120  
   121  					BeforeEach(func() {
   122  						routerGroup = helpers.NewRouterGroup(helpers.NewRouterGroupName(), "1024-2048")
   123  						routerGroup.Create()
   124  
   125  						tcpDomain = helpers.NewDomain(orgName, helpers.NewDomainName("TCP-DOMAIN"))
   126  						tcpDomain.CreateWithRouterGroup(routerGroup.Name)
   127  
   128  						port = 1024
   129  
   130  						Eventually(helpers.CF("create-route", tcpDomain.Name, "--port", fmt.Sprintf("%d", port))).Should(Exit(0))
   131  					})
   132  
   133  					AfterEach(func() {
   134  						tcpDomain.DeleteShared()
   135  						routerGroup.Delete()
   136  					})
   137  
   138  					It("tells the user the route exists and exits without failing", func() {
   139  						session := helpers.CF("check-route", tcpDomain.Name, "--port", fmt.Sprintf("%d", port))
   140  						Eventually(session).Should(Say(`Checking for route\.\.\.`))
   141  						Eventually(session).Should(Say(`Route '%s:%d' does exist\.`, tcpDomain.Name, port))
   142  						Eventually(session).Should(Say(`OK`))
   143  						Eventually(session).Should(Exit(0))
   144  					})
   145  				})
   146  			})
   147  
   148  			When("the route does not already exist", func() {
   149  				var domain helpers.Domain
   150  
   151  				BeforeEach(func() {
   152  					domain = helpers.NewDomain(orgName, domainName)
   153  					domain.Create()
   154  				})
   155  
   156  				AfterEach(func() {
   157  					domain.Delete()
   158  				})
   159  
   160  				When("no flags are used", func() {
   161  					It("checks the route", func() {
   162  						session := helpers.CF("check-route", domainName)
   163  						Eventually(session).Should(Say(`Checking for route\.\.\.`))
   164  						Eventually(session).Should(Say(`Route '%s' does not exist\.`, domainName))
   165  						Eventually(session).Should(Exit(0))
   166  					})
   167  				})
   168  
   169  				When("passing in a hostname", func() {
   170  					It("checks the route with the hostname", func() {
   171  						hostname := "tiramisu"
   172  						session := helpers.CF("check-route", domainName, "-n", hostname)
   173  						Eventually(session).Should(Say(`Checking for route\.\.\.`))
   174  						Eventually(session).Should(Say(`Route '%s\.%s' does not exist\.`, hostname, domainName))
   175  						Eventually(session).Should(Exit(0))
   176  					})
   177  				})
   178  
   179  				When("passing in hostname and path with a leading '/'", func() {
   180  					It("checks the route with hostname and path", func() {
   181  						hostname := "tiramisu"
   182  						pathString := "/recipes"
   183  						session := helpers.CF("check-route", domainName, "-n", hostname, "--path", pathString)
   184  						Eventually(session).Should(Say(`Checking for route\.\.\.`))
   185  						Eventually(session).Should(Say(`Route '%s\.%s%s' does not exist\.`, hostname, domainName, pathString))
   186  						Eventually(session).Should(Exit(0))
   187  					})
   188  				})
   189  
   190  				When("passing in hostname and path without a leading '/'", func() {
   191  					It("checks the route with hostname and path", func() {
   192  						hostname := "tiramisu"
   193  						pathString := "more-recipes"
   194  						session := helpers.CF("check-route", domainName, "-n", hostname, "--path", pathString)
   195  						Eventually(session).Should(Say(`Checking for route\.\.\.`))
   196  						Eventually(session).Should(Say(`Route '%s\.%s\/%s' does not exist\.`, hostname, domainName, pathString))
   197  						Eventually(session).Should(Exit(0))
   198  					})
   199  				})
   200  			})
   201  		})
   202  
   203  		When("the domain does not exist", func() {
   204  			It("displays error and exits 1", func() {
   205  				session := helpers.CF("check-route", "some-domain")
   206  				Eventually(session).Should(Say(`FAILED`))
   207  				Eventually(session.Err).Should(Say(`Domain 'some-domain' not found.`))
   208  				Eventually(session).Should(Exit(1))
   209  			})
   210  		})
   211  
   212  		When("the domain is not specified", func() {
   213  			It("displays error and exits 1", func() {
   214  				session := helpers.CF("check-route")
   215  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `DOMAIN` was not provided\n"))
   216  				Eventually(session.Err).Should(Say("\n"))
   217  				Eventually(session).Should(Say("NAME:\n"))
   218  				Eventually(session).Should(Exit(1))
   219  			})
   220  		})
   221  	})
   222  })