github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/push/hostname_only_routing_test.go (about)

     1  package push
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     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("push with hostname", func() {
    16  	var (
    17  		appName string
    18  		route   string
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		appName = helpers.NewAppName()
    23  	})
    24  
    25  	Context("when the default domain is a HTTP domain", func() {
    26  		Context("when no host is provided / host defaults to app name", func() {
    27  			BeforeEach(func() {
    28  				route = fmt.Sprintf("%s.%s", strings.ToLower(appName), defaultSharedDomain())
    29  			})
    30  
    31  			Context("when the default route does not exist", func() {
    32  				It("creates and maps the route", func() {
    33  					helpers.WithHelloWorldApp(func(dir string) {
    34  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start")
    35  						Eventually(session).Should(Say("routes:"))
    36  						Eventually(session).Should(Say("(?i)\\+\\s+%s", route))
    37  						Eventually(session).Should(Exit(0))
    38  					})
    39  
    40  					session := helpers.CF("app", appName)
    41  					Eventually(session).Should(Say("name:\\s+%s", appName))
    42  					Eventually(session).Should(Say("routes:\\s+%s", route))
    43  					Eventually(session).Should(Exit(0))
    44  				})
    45  			})
    46  
    47  			Context("the default route exists and is unmapped", func() {
    48  				BeforeEach(func() {
    49  					Eventually(helpers.CF("create-route", space, defaultSharedDomain(), "-n", strings.ToLower(appName))).Should(Exit(0))
    50  				})
    51  
    52  				It("maps the route", func() {
    53  					helpers.WithHelloWorldApp(func(dir string) {
    54  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start")
    55  						Eventually(session).Should(Say("routes:"))
    56  						Eventually(session).Should(Say("(?i)\\+\\s+%s", route))
    57  						Eventually(session).Should(Exit(0))
    58  					})
    59  
    60  					session := helpers.CF("app", appName)
    61  					Eventually(session).Should(Say("name:\\s+%s", appName))
    62  					Eventually(session).Should(Say("routes:\\s+%s", route))
    63  					Eventually(session).Should(Exit(0))
    64  				})
    65  			})
    66  
    67  			Context("when the default route is mapped to the application", func() {
    68  				BeforeEach(func() {
    69  					helpers.WithHelloWorldApp(func(dir string) {
    70  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start")).Should(Exit(0))
    71  					})
    72  				})
    73  
    74  				It("does nothing", func() {
    75  					helpers.WithHelloWorldApp(func(dir string) {
    76  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start")
    77  						Eventually(session).Should(Say("routes:"))
    78  						Eventually(session).Should(Say("(?i)\\s+%s", route))
    79  						Eventually(session).Should(Exit(0))
    80  					})
    81  
    82  					session := helpers.CF("app", appName)
    83  					Eventually(session).Should(Say("name:\\s+%s", appName))
    84  					Eventually(session).Should(Say("routes:\\s+%s", route))
    85  					Eventually(session).Should(Exit(0))
    86  				})
    87  			})
    88  		})
    89  
    90  		Context("when the host is provided", func() {
    91  			var hostname string
    92  
    93  			BeforeEach(func() {
    94  				hostname = strings.ToLower(helpers.NewAppName())
    95  				route = fmt.Sprintf("%s.%s", hostname, defaultSharedDomain())
    96  			})
    97  
    98  			Context("when the default route does not exist", func() {
    99  				It("creates and maps the route", func() {
   100  					helpers.WithHelloWorldApp(func(dir string) {
   101  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--hostname", hostname, "--no-start")
   102  						Eventually(session).Should(Say("routes:"))
   103  						Eventually(session).Should(Say("(?i)\\+\\s+%s", route))
   104  						Eventually(session).Should(Exit(0))
   105  					})
   106  
   107  					session := helpers.CF("app", appName)
   108  					Eventually(session).Should(Say("name:\\s+%s", appName))
   109  					Eventually(session).Should(Say("routes:\\s+%s", route))
   110  					Eventually(session).Should(Exit(0))
   111  
   112  					By("does not remap default route after")
   113  					helpers.WithHelloWorldApp(func(dir string) {
   114  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start")
   115  						Eventually(session).Should(Say("routes:"))
   116  						Consistently(session).ShouldNot(Say("(?i)\\+\\s+.*%s.*", defaultSharedDomain()))
   117  						Eventually(session).Should(Exit(0))
   118  					})
   119  				})
   120  			})
   121  
   122  			Context("the default route exists and is unmapped", func() {
   123  				BeforeEach(func() {
   124  					Eventually(helpers.CF("create-route", space, defaultSharedDomain(), "-n", strings.ToLower(appName))).Should(Exit(0))
   125  				})
   126  
   127  				It("creates and maps the route with the provided hostname", func() {
   128  					helpers.WithHelloWorldApp(func(dir string) {
   129  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--hostname", hostname, "--no-start")
   130  						Eventually(session).Should(Say("routes:"))
   131  						Eventually(session).Should(Say("(?i)\\+\\s+%s", route))
   132  						Eventually(session).Should(Exit(0))
   133  					})
   134  
   135  					session := helpers.CF("app", appName)
   136  					Eventually(session).Should(Say("name:\\s+%s", appName))
   137  					Eventually(session).Should(Say("routes:\\s+%s", route))
   138  					Eventually(session).Should(Exit(0))
   139  				})
   140  			})
   141  
   142  			Context("when the default route is mapped to the application", func() {
   143  				BeforeEach(func() {
   144  					helpers.WithHelloWorldApp(func(dir string) {
   145  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--hostname", hostname, "--no-start")).Should(Exit(0))
   146  					})
   147  				})
   148  
   149  				It("does nothing", func() {
   150  					helpers.WithHelloWorldApp(func(dir string) {
   151  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--hostname", hostname, "--no-start")
   152  						Eventually(session).Should(Say("routes:"))
   153  						Eventually(session).Should(Say("(?i)\\s+%s", route))
   154  						Eventually(session).Should(Exit(0))
   155  					})
   156  
   157  					session := helpers.CF("app", appName)
   158  					Eventually(session).Should(Say("name:\\s+%s", appName))
   159  					Eventually(session).Should(Say("routes:\\s+%s", route))
   160  					Eventually(session).Should(Exit(0))
   161  				})
   162  			})
   163  		})
   164  	})
   165  
   166  	Context("when using a tcp domain", func() {
   167  		var (
   168  			domain     helpers.Domain
   169  			domainName string
   170  		)
   171  
   172  		BeforeEach(func() {
   173  			domainName = helpers.DomainName()
   174  			domain = helpers.NewDomain(organization, domainName)
   175  			domain.CreateWithRouterGroup(helpers.FindOrCreateTCPRouterGroup(GinkgoParallelNode()))
   176  		})
   177  
   178  		AfterEach(func() {
   179  			domain.DeleteShared()
   180  		})
   181  
   182  		It("returns an error", func() {
   183  			session := helpers.CF(PushCommandName, appName, "--hostname", "I-dont-care", "-d", domainName, "--no-start")
   184  			Eventually(session.Err).Should(Say("The route is invalid: a hostname cannot be used with a TCP domain."))
   185  			Eventually(session).Should(Exit(1))
   186  		})
   187  	})
   188  })