github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/push/http_routes_in_manifest_test.go (about) 1 package push 2 3 import ( 4 "path/filepath" 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 routes in manifest", func() { 15 var ( 16 app string 17 domain helpers.Domain 18 subdomain helpers.Domain 19 route1 helpers.Route 20 route2 helpers.Route 21 ) 22 23 BeforeEach(func() { 24 app = helpers.NewAppName() 25 domain = helpers.NewDomain(organization, helpers.DomainName()) 26 subdomain = helpers.NewDomain(organization, "sub."+domain.Name) 27 route1 = helpers.NewRoute(space, domain.Name, helpers.PrefixedRandomName("r1"), "") 28 route2 = helpers.NewRoute(space, subdomain.Name, helpers.PrefixedRandomName("r2"), "") 29 }) 30 31 Context("when the domain exist", func() { 32 BeforeEach(func() { 33 domain.Create() 34 subdomain.Create() 35 }) 36 37 Context("when the routes are new", func() { 38 It("creates and binds 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) 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 Context("when one of the routes exists", func() { 71 Context("when the route is in the current space", func() { 72 BeforeEach(func() { 73 route2.Create() 74 }) 75 76 It("creates and binds the new route; binds 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) 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 Context("when the route is in a different space", func() { 109 BeforeEach(func() { 110 otherSpace := helpers.NewSpaceName() 111 helpers.CreateSpace(otherSpace) 112 route2.Space = otherSpace 113 route2.Create() 114 }) 115 116 It("returns an error", func() { 117 helpers.WithHelloWorldApp(func(dir string) { 118 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 119 "applications": []map[string]interface{}{ 120 { 121 "name": app, 122 "routes": []map[string]string{ 123 {"route": route1.String()}, 124 {"route": route2.String()}, 125 }, 126 }, 127 }, 128 }) 129 130 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName) 131 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 132 Eventually(session.Err).Should(Say("The route %s is already in use.", route2)) 133 Eventually(session.Err).Should(Say("TIP: Change the hostname with -n HOSTNAME or use --random-route to generate a new route and then push again.")) 134 Eventually(session).Should(Exit(1)) 135 }) 136 }) 137 }) 138 }) 139 140 Context("when the route contains a port", func() { 141 BeforeEach(func() { 142 route1 = helpers.NewTCPRoute(space, domain.Name, 1234) 143 }) 144 145 It("returns an error", func() { 146 helpers.WithHelloWorldApp(func(dir string) { 147 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 148 "applications": []map[string]interface{}{ 149 { 150 "name": app, 151 "routes": []map[string]string{ 152 {"route": route1.String()}, 153 {"route": route2.String()}, 154 }, 155 }, 156 }, 157 }) 158 159 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName) 160 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 161 Eventually(session.Err).Should(Say("Port not allowed in HTTP domain %s", domain.Name)) 162 Eventually(session).Should(Exit(1)) 163 }) 164 }) 165 }) 166 }) 167 168 Context("when the domain does not exist", func() { 169 It("returns an error", func() { 170 helpers.WithHelloWorldApp(func(dir string) { 171 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 172 "applications": []map[string]interface{}{ 173 { 174 "name": app, 175 "routes": []map[string]string{ 176 {"route": route1.String()}, 177 {"route": route2.String()}, 178 }, 179 }, 180 }, 181 }) 182 183 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName) 184 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 185 Eventually(session.Err).Should(Say("The route %s did not match any existing domains.", route1)) 186 Eventually(session).Should(Exit(1)) 187 }) 188 }) 189 }) 190 })