Skip to content

Commit 7bbb6e0

Browse files
Dariquesta18e
authored andcommitted
New test with a websocket app
1 parent d88aaef commit 7bbb6e0

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

src/code.cloudfoundry.org/gorouter/integration/route_services_test.go

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ var _ = Describe("Route services", func() {
2121
var testState *testState
2222

2323
const (
24-
appHostname = "app-with-route-service.some.domain"
24+
appHostname = "app-with-route-service.some.domain"
25+
wsAppHostname = "ws-app-with-route-service.some.domain"
2526
)
2627

2728
var (
@@ -84,6 +85,60 @@ var _ = Describe("Route services", func() {
8485
return fmt.Sprintf("https://%s:%s", testState.trustedExternalServiceHostname, port)
8586
}
8687

88+
Context("Happy Path with a web socket app with a route service", func() {
89+
Context("When an app is registered with a simple route service", func() {
90+
var (
91+
wsApp *httptest.Server
92+
)
93+
BeforeEach(func() {
94+
testState.StartGorouterOrFail()
95+
routeService.Start()
96+
wsApp = httptest.NewServer(http.HandlerFunc(
97+
func(w http.ResponseWriter, r *http.Request) {
98+
w.Header().Add("X-App-Instance", "ws-app")
99+
w.Header().Set("Upgrade", "websocket")
100+
w.Header().Set("Connection", "upgrade")
101+
w.WriteHeader(200)
102+
_, err := w.Write([]byte("I'm the websocket app"))
103+
Expect(err).ToNot(HaveOccurred())
104+
}))
105+
106+
testState.registerWithInternalRouteService(
107+
wsApp,
108+
routeService,
109+
wsAppHostname,
110+
testState.cfg.SSLPort,
111+
)
112+
})
113+
114+
It("succeeds", func() {
115+
req := testState.newGetRequest(
116+
fmt.Sprintf("https://%s", wsAppHostname),
117+
)
118+
119+
res, err := testState.client.Do(req)
120+
Expect(err).ToNot(HaveOccurred())
121+
Expect(res.StatusCode).To(Equal(http.StatusOK))
122+
body, err := io.ReadAll(res.Body)
123+
Expect(err).ToNot(HaveOccurred())
124+
Expect(body).To(Equal([]byte("I'm the route service")))
125+
})
126+
127+
It("properly URL-encodes and decodes", func() {
128+
req := testState.newGetRequest(
129+
fmt.Sprintf("https://%s?%s", wsAppHostname, "param=a%0Ab"),
130+
)
131+
132+
res, err := testState.client.Do(req)
133+
Expect(err).ToNot(HaveOccurred())
134+
Expect(res.StatusCode).To(Equal(http.StatusOK))
135+
body, err := io.ReadAll(res.Body)
136+
Expect(err).ToNot(HaveOccurred())
137+
Expect(body).To(Equal([]byte("I'm the route service")))
138+
})
139+
})
140+
})
141+
87142
Context("Happy Path", func() {
88143
Context("When an app is registered with a simple route service", func() {
89144
BeforeEach(func() {

0 commit comments

Comments
 (0)