github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/integration/push/tcp_routes_in_manifest_test.go (about)

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