github.com/loafoe/cli@v7.1.0+incompatible/integration/v6/push/tcp_routes_in_manifest_test.go (about)

     1  package push
     2  
     3  import (
     4  	"path/filepath"
     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("TCP routes in manifest", func() {
    14  	var (
    15  		app    string
    16  		domain helpers.Domain
    17  		route1 helpers.Route
    18  		route2 helpers.Route
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		app = helpers.NewAppName()
    23  		domain = helpers.NewDomain(organization, helpers.NewDomainName())
    24  		route1 = helpers.NewTCPRoute(space, domain.Name, 1024)
    25  		route2 = helpers.NewTCPRoute(space, domain.Name, 1025)
    26  	})
    27  
    28  	When("the domain exists", func() {
    29  		BeforeEach(func() {
    30  			domain.CreateWithRouterGroup(helpers.FindOrCreateTCPRouterGroup(GinkgoParallelNode()))
    31  		})
    32  
    33  		AfterEach(func() {
    34  			domain.DeleteShared()
    35  		})
    36  
    37  		When("the routes are new", func() {
    38  			It("creates and maps the routes", func() {
    39  				helpers.WithHelloWorldApp(func(dir string) {
    40  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
    41  						"applications": []map[string]interface{}{
    42  							{
    43  								"name": app,
    44  								"routes": []map[string]string{
    45  									{"route": route1.String()},
    46  									{"route": route2.String()},
    47  								},
    48  							},
    49  						},
    50  					})
    51  
    52  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
    53  					Eventually(session).Should(Say(`Getting app info\.\.\.`))
    54  
    55  					Eventually(session).Should(Say(`Creating app with these attributes\.\.\.`))
    56  					Eventually(session).Should(Say(`\+\s+name:\s+%s`, app))
    57  					Eventually(session).Should(Say(`\s+routes:`))
    58  					Eventually(session).Should(Say(`(?i)\+\s+%s`, route1))
    59  					Eventually(session).Should(Say(`(?i)\+\s+%s`, route2))
    60  					Eventually(session).Should(Exit(0))
    61  				})
    62  
    63  				session := helpers.CF("app", app)
    64  				Eventually(session).Should(Say(`name:\s+%s`, app))
    65  				Eventually(session).Should(Say(`routes:\s+(%s, %s)|(%s, %s)`, route1, route2, route2, route1))
    66  				Eventually(session).Should(Exit(0))
    67  			})
    68  		})
    69  
    70  		When("a route already exist", func() {
    71  			When("the routes exist in the current space", func() {
    72  				BeforeEach(func() {
    73  					route2.Create()
    74  				})
    75  
    76  				It("creates and maps the new route; maps the old route", func() {
    77  					helpers.WithHelloWorldApp(func(dir string) {
    78  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
    79  							"applications": []map[string]interface{}{
    80  								{
    81  									"name": app,
    82  									"routes": []map[string]string{
    83  										{"route": route1.String()},
    84  										{"route": route2.String()},
    85  									},
    86  								},
    87  							},
    88  						})
    89  
    90  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
    91  						Eventually(session).Should(Say(`Getting app info\.\.\.`))
    92  
    93  						Eventually(session).Should(Say(`Creating app with these attributes\.\.\.`))
    94  						Eventually(session).Should(Say(`\+\s+name:\s+%s`, app))
    95  						Eventually(session).Should(Say(`\s+routes:`))
    96  						Eventually(session).Should(Say(`(?i)\+\s+%s`, route1))
    97  						Eventually(session).Should(Say(`(?i)\+\s+%s`, route2))
    98  						Eventually(session).Should(Exit(0))
    99  					})
   100  
   101  					session := helpers.CF("app", app)
   102  					Eventually(session).Should(Say(`name:\s+%s`, app))
   103  					Eventually(session).Should(Say(`routes:\s+(%s, %s)|(%s, %s)`, route1, route2, route2, route1))
   104  					Eventually(session).Should(Exit(0))
   105  				})
   106  			})
   107  
   108  			When("the routes exist in another space", func() {
   109  				var otherSpace string
   110  
   111  				BeforeEach(func() {
   112  					otherSpace = helpers.NewSpaceName()
   113  					helpers.CreateSpace(otherSpace)
   114  					route2.Space = otherSpace
   115  					route2.Create()
   116  				})
   117  
   118  				AfterEach(func() {
   119  					helpers.QuickDeleteSpace(otherSpace)
   120  				})
   121  
   122  				It("returns an error", func() {
   123  					helpers.WithHelloWorldApp(func(dir string) {
   124  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   125  							"applications": []map[string]interface{}{
   126  								{
   127  									"name": app,
   128  									"routes": []map[string]string{
   129  										{"route": route1.String()},
   130  										{"route": route2.String()},
   131  									},
   132  								},
   133  							},
   134  						})
   135  
   136  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   137  						Eventually(session).Should(Say(`Getting app info\.\.\.`))
   138  						Eventually(session.Err).Should(Say("The app cannot be mapped to route %s because the route exists in a different space.", route2))
   139  						Eventually(session).Should(Exit(1))
   140  					})
   141  				})
   142  			})
   143  		})
   144  
   145  		When("a host is provided", func() {
   146  			BeforeEach(func() {
   147  				route1.Host = "some-host"
   148  			})
   149  
   150  			It("returns an error", func() {
   151  				helpers.WithHelloWorldApp(func(dir string) {
   152  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   153  						"applications": []map[string]interface{}{
   154  							{
   155  								"name": app,
   156  								"routes": []map[string]string{
   157  									{"route": route1.String()},
   158  									{"route": route2.String()},
   159  								},
   160  							},
   161  						},
   162  					})
   163  
   164  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   165  					Eventually(session).Should(Say(`Getting app info\.\.\.`))
   166  					Eventually(session.Err).Should(Say("Host and path not allowed in route with TCP domain %s", route1.Domain))
   167  					Eventually(session).Should(Exit(1))
   168  				})
   169  			})
   170  		})
   171  
   172  		When("an path is provided", func() {
   173  			It("returns an error", func() {
   174  				helpers.WithHelloWorldApp(func(dir string) {
   175  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   176  						"applications": []map[string]interface{}{
   177  							{
   178  								"name": app,
   179  								"routes": []map[string]string{
   180  									{"route": route1.String() + "/some-path"},
   181  								},
   182  							},
   183  						},
   184  					})
   185  
   186  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   187  					Eventually(session.Err).Should(Say("Host and path not allowed in route with TCP domain %s", route1.Domain))
   188  					Eventually(session).Should(Exit(1))
   189  				})
   190  			})
   191  		})
   192  	})
   193  
   194  	When("the domains don't exist", func() {
   195  		It("returns an error", func() {
   196  			helpers.WithHelloWorldApp(func(dir string) {
   197  				helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   198  					"applications": []map[string]interface{}{
   199  						{
   200  							"name": app,
   201  							"routes": []map[string]string{
   202  								{"route": route1.String()},
   203  							},
   204  						},
   205  					},
   206  				})
   207  
   208  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   209  				Eventually(session).Should(Say(`Getting app info\.\.\.`))
   210  				Eventually(session.Err).Should(Say("The route %s did not match any existing domains.", route1))
   211  				Eventually(session).Should(Exit(1))
   212  			})
   213  		})
   214  	})
   215  })