github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v6/push/http_random_route_test.go (about)

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