github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v7/isolated/create_route_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("create-route command", func() {
    13  	Context("Help", func() {
    14  		It("appears in cf help -a", func() {
    15  			session := helpers.CF("help", "-a")
    16  			Eventually(session).Should(Exit(0))
    17  			Expect(session).To(HaveCommandInCategoryWithDescription("create-route", "ROUTES", "Create a route for later use"))
    18  		})
    19  
    20  		It("displays the help information", func() {
    21  			session := helpers.CF("create-route", "--help")
    22  			Eventually(session).Should(Say(`NAME:`))
    23  			Eventually(session).Should(Say(`create-route - Create a route for later use\n`))
    24  			Eventually(session).Should(Say(`\n`))
    25  
    26  			Eventually(session).Should(Say(`USAGE:`))
    27  			Eventually(session).Should(Say(`cf create-route DOMAIN \[--hostname HOSTNAME\] \[--path PATH\]\n`))
    28  			Eventually(session).Should(Say(`\n`))
    29  
    30  			Eventually(session).Should(Say(`EXAMPLES:`))
    31  			Eventually(session).Should(Say(`cf create-route example.com\s+# example.com`))
    32  			Eventually(session).Should(Say(`cf create-route example.com --hostname myapp\s+# myapp.example.com`))
    33  			Eventually(session).Should(Say(`cf create-route example.com --hostname myapp --path foo\s+# myapp.example.com/foo`))
    34  			Eventually(session).Should(Say(`\n`))
    35  
    36  			Eventually(session).Should(Say(`OPTIONS:`))
    37  			Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`))
    38  			Eventually(session).Should(Say(`--path\s+Path for the HTTP route`))
    39  			Eventually(session).Should(Say(`\n`))
    40  
    41  			Eventually(session).Should(Say(`SEE ALSO:`))
    42  			Eventually(session).Should(Say(`check-route, domains, map-route, routes, unmap-route`))
    43  
    44  			Eventually(session).Should(Exit(0))
    45  		})
    46  	})
    47  
    48  	When("the environment is not setup correctly", func() {
    49  		It("fails with the appropriate errors", func() {
    50  			helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "create-route", "some-domain")
    51  		})
    52  	})
    53  
    54  	When("the environment is set up correctly", func() {
    55  		var (
    56  			orgName   string
    57  			spaceName string
    58  		)
    59  
    60  		BeforeEach(func() {
    61  			orgName = helpers.NewOrgName()
    62  			spaceName = helpers.NewSpaceName()
    63  
    64  			helpers.SetupCF(orgName, spaceName)
    65  		})
    66  
    67  		AfterEach(func() {
    68  			helpers.QuickDeleteOrg(orgName)
    69  		})
    70  
    71  		When("the space and domain exist", func() {
    72  			var (
    73  				userName   string
    74  				domainName string
    75  			)
    76  
    77  			BeforeEach(func() {
    78  				domainName = helpers.NewDomainName()
    79  				userName, _ = helpers.GetCredentials()
    80  			})
    81  
    82  			When("the route already exists", func() {
    83  				var (
    84  					domain   helpers.Domain
    85  					hostname string
    86  				)
    87  
    88  				BeforeEach(func() {
    89  					domain = helpers.NewDomain(orgName, domainName)
    90  					hostname = "key-lime-pie"
    91  					domain.CreatePrivate()
    92  					Eventually(helpers.CF("create-route", domainName, "--hostname", hostname)).Should(Exit(0))
    93  				})
    94  
    95  				AfterEach(func() {
    96  					domain.Delete()
    97  				})
    98  
    99  				It("warns the user that it has already been created and runs to completion without failing", func() {
   100  					session := helpers.CF("create-route", domainName, "--hostname", hostname)
   101  					Eventually(session).Should(Say(`Creating route %s\.%s for org %s / space %s as %s\.\.\.`, hostname, domainName, orgName, spaceName, userName))
   102  					Eventually(session.Err).Should(Say(`Route already exists with host '%s' for domain '%s'\.`, hostname, domainName))
   103  					Eventually(session).Should(Say(`OK`))
   104  					Eventually(session).Should(Exit(0))
   105  				})
   106  			})
   107  
   108  			When("the route does not already exist", func() {
   109  				When("the domain is private", func() {
   110  					var domain helpers.Domain
   111  
   112  					BeforeEach(func() {
   113  						domain = helpers.NewDomain(orgName, domainName)
   114  						domain.Create()
   115  					})
   116  
   117  					AfterEach(func() {
   118  						domain.Delete()
   119  					})
   120  
   121  					When("no flags are used", func() {
   122  						It("creates the route", func() {
   123  							session := helpers.CF("create-route", domainName)
   124  							Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName))
   125  							Eventually(session).Should(Say(`Route %s has been created\.`, domainName))
   126  							Eventually(session).Should(Exit(0))
   127  						})
   128  					})
   129  
   130  					When("passing in a hostname", func() {
   131  						It("creates the route with the hostname", func() {
   132  							hostname := "tiramisu"
   133  							session := helpers.CF("create-route", domainName, "-n", hostname)
   134  							Eventually(session).Should(Say(`Creating route %s\.%s for org %s / space %s as %s\.\.\.`, hostname, domainName, orgName, spaceName, userName))
   135  							Eventually(session).Should(Say(`Route %s\.%s has been created\.`, hostname, domainName))
   136  							Eventually(session).Should(Exit(0))
   137  						})
   138  					})
   139  
   140  					When("passing in hostname and path with a leading '/'", func() {
   141  						It("creates the route with hostname and path", func() {
   142  							hostname := "tiramisu"
   143  							pathString := "/recipes"
   144  							session := helpers.CF("create-route", domainName, "-n", hostname, "--path", pathString)
   145  							Eventually(session).Should(Say(`Creating route %s\.%s%s for org %s / space %s as %s\.\.\.`, hostname, domainName, pathString, orgName, spaceName, userName))
   146  							Eventually(session).Should(Say(`Route %s\.%s%s has been created\.`, hostname, domainName, pathString))
   147  							Eventually(session).Should(Exit(0))
   148  						})
   149  					})
   150  
   151  					When("passing in hostname and path without a leading '/'", func() {
   152  						It("creates the route with hostname and path", func() {
   153  							hostname := "tiramisu"
   154  							pathString := "more-recipes"
   155  							session := helpers.CF("create-route", domainName, "-n", hostname, "--path", pathString)
   156  							Eventually(session).Should(Say(`Creating route %s\.%s\/%s for org %s / space %s as %s\.\.\.`, hostname, domainName, pathString, orgName, spaceName, userName))
   157  							Eventually(session).Should(Say(`Route %s\.%s\/%s has been created\.`, hostname, domainName, pathString))
   158  							Eventually(session).Should(Exit(0))
   159  						})
   160  					})
   161  				})
   162  
   163  				When("the domain is shared", func() {
   164  					var domain helpers.Domain
   165  
   166  					BeforeEach(func() {
   167  						domain = helpers.NewDomain("", domainName)
   168  						domain.CreateShared()
   169  					})
   170  
   171  					AfterEach(func() {
   172  						domain.DeleteShared()
   173  					})
   174  
   175  					When("no flags are used", func() {
   176  						It("errors indicating that hostname is missing", func() {
   177  							session := helpers.CF("create-route", domainName)
   178  							Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName))
   179  							Eventually(session.Out).Should(Say(`FAILED`))
   180  							Eventually(session.Err).Should(Say(`Missing host. Routes in shared domains must have a host defined.`))
   181  							Eventually(session).Should(Exit(1))
   182  						})
   183  					})
   184  
   185  					When("passing in a hostname", func() {
   186  						It("creates the route with the hostname", func() {
   187  							hostname := "tiramisu"
   188  							session := helpers.CF("create-route", domainName, "-n", hostname)
   189  							Eventually(session).Should(Say(`Creating route %s\.%s for org %s / space %s as %s\.\.\.`, hostname, domainName, orgName, spaceName, userName))
   190  							Eventually(session).Should(Say(`Route %s\.%s has been created\.`, hostname, domainName))
   191  							Eventually(session).Should(Exit(0))
   192  						})
   193  					})
   194  
   195  					When("passing in a hostname and path", func() {
   196  						It("creates the route with the hostname", func() {
   197  							hostname := "tiramisu"
   198  							path := "lion"
   199  							session := helpers.CF("create-route", domainName, "-n", hostname, "--path", path)
   200  							Eventually(session).Should(Say(`Creating route %s\.%s\/%s for org %s / space %s as %s\.\.\.`, hostname, domainName, path, orgName, spaceName, userName))
   201  							Eventually(session).Should(Say(`Route %s\.%s\/%s has been created\.`, hostname, domainName, path))
   202  							Eventually(session).Should(Exit(0))
   203  						})
   204  					})
   205  				})
   206  			})
   207  		})
   208  
   209  		When("the domain does not exist", func() {
   210  			It("displays error and exits 1", func() {
   211  				session := helpers.CF("create-route", "some-domain")
   212  				Eventually(session).Should(Say(`FAILED`))
   213  				Eventually(session.Err).Should(Say(`Domain 'some-domain' not found.`))
   214  				Eventually(session).Should(Exit(1))
   215  			})
   216  		})
   217  
   218  		When("the domain is not specified", func() {
   219  			It("displays error and exits 1", func() {
   220  				session := helpers.CF("create-route")
   221  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `DOMAIN` was not provided\n"))
   222  				Eventually(session.Err).Should(Say("\n"))
   223  				Eventually(session).Should(Say("NAME:\n"))
   224  				Eventually(session).Should(Exit(1))
   225  			})
   226  		})
   227  	})
   228  })