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

     1  package push
     2  
     3  import (
     4  	"path"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  
     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("HTTP random route", func() {
    15  	var (
    16  		appName string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		appName = "short-app-name" // used on purpose to fit route length requirement
    21  	})
    22  
    23  	Context("when passed the --random-route flag", func() {
    24  		Context("when the app does not already exist", func() {
    25  			It("generates a random route for the app", func() {
    26  				helpers.WithHelloWorldApp(func(dir string) {
    27  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--random-route", "--no-start")
    28  					Eventually(session).Should(Say("routes:"))
    29  					Eventually(session).Should(Say("(?i)\\+\\s+%s-[\\w]+-[\\w]+.%s", appName, defaultSharedDomain()))
    30  					Eventually(session).Should(Exit(0))
    31  				})
    32  
    33  				appSession := helpers.CF("app", appName)
    34  				Eventually(appSession).Should(Say("name:\\s+%s", appName))
    35  				Eventually(appSession).Should(Say("(?i)routes:\\s+%s-[\\w]+-[\\w]+.%s", appName, defaultSharedDomain()))
    36  				Eventually(appSession).Should(Exit(0))
    37  			})
    38  		})
    39  
    40  		Context("when the app exists and has an existing route", func() {
    41  			It("does not generate a random route for the app", func() {
    42  				helpers.WithHelloWorldApp(func(dir string) {
    43  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--random-route", "--no-start")
    44  					Eventually(session).ShouldNot(Say("\\+\\s+%s-[\\w]+", appName))
    45  					Eventually(session).Should(Exit(0))
    46  				})
    47  			})
    48  
    49  			Context("when also passed an http domain", func() {
    50  				var domain helpers.Domain
    51  
    52  				BeforeEach(func() {
    53  					domain = helpers.NewDomain(organization, helpers.DomainName("some-domain"))
    54  					domain.Create()
    55  				})
    56  
    57  				AfterEach(func() {
    58  					domain.Delete()
    59  				})
    60  
    61  				It("does not create a new route with the provided domain name", func() {
    62  					helpers.WithHelloWorldApp(func(dir string) {
    63  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--random-route", "-d", domain.Name, "--no-start")
    64  						Eventually(session).ShouldNot(Say("(?i)\\+\\s+%s-[\\w]+-[\\w]+.%s", appName, domain.Name))
    65  						Eventually(session).Should(Exit(0))
    66  					})
    67  				})
    68  			})
    69  		})
    70  
    71  		Context("when also passed an http domain", func() {
    72  			var domain helpers.Domain
    73  
    74  			BeforeEach(func() {
    75  				domain = helpers.NewDomain(organization, helpers.DomainName("some-domain"))
    76  				domain.Create()
    77  			})
    78  
    79  			AfterEach(func() {
    80  				domain.Delete()
    81  			})
    82  
    83  			It("creates a new route with the provided domain", func() {
    84  				helpers.WithHelloWorldApp(func(dir string) {
    85  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--random-route", "-d", domain.Name, "--no-start")
    86  					Eventually(session).Should(Say("(?i)\\+\\s+%s-[\\w]+-[\\w]+.%s", appName, domain.Name))
    87  					Eventually(session).Should(Exit(0))
    88  				})
    89  			})
    90  		})
    91  	})
    92  
    93  	Context("when passed the random-route manifest property", func() {
    94  		var manifest map[string]interface{}
    95  
    96  		BeforeEach(func() {
    97  			manifest = map[string]interface{}{
    98  				"applications": []map[string]interface{}{
    99  					{
   100  						"name":         appName,
   101  						"random-route": true,
   102  					},
   103  				},
   104  			}
   105  
   106  			helpers.WithHelloWorldApp(func(dir string) {
   107  				helpers.WriteManifest(path.Join(dir, "manifest.yml"), manifest)
   108  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start")
   109  				Eventually(session).Should(Say("routes:"))
   110  				Eventually(session).Should(Say("(?i)\\+\\s+%s-[\\w]+-[\\w]+.%s", appName, defaultSharedDomain()))
   111  				Eventually(session).Should(Exit(0))
   112  			})
   113  		})
   114  
   115  		It("generates a random route for the app", func() {
   116  			session := helpers.CF("app", appName)
   117  			Eventually(session).Should(Say("name:\\s+%s", appName))
   118  			Eventually(session).Should(Say("(?i)routes:\\s+%s-[\\w]+-[\\w]+.%s", appName, defaultSharedDomain()))
   119  			Eventually(session).Should(Exit(0))
   120  		})
   121  
   122  		Context("when the app has an existing route", func() {
   123  			It("does not generate a random route for the app", func() {
   124  				helpers.WithHelloWorldApp(func(dir string) {
   125  					helpers.WriteManifest(path.Join(dir, "manifest.yml"), manifest)
   126  
   127  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start")
   128  					Eventually(session).ShouldNot(Say("\\+\\s+%s-[\\w]+", appName))
   129  					Eventually(session).Should(Exit(0))
   130  				})
   131  			})
   132  		})
   133  	})
   134  })