Skip to content

Commit 2dda695

Browse files
committed
tests: rename tests
1 parent a0bcd32 commit 2dda695

22 files changed

+345
-433
lines changed

buffer/buffer_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/vulcand/oxy/v2/utils"
1919
)
2020

21-
func TestSimple(t *testing.T) {
21+
func TestBuffer_simple(t *testing.T) {
2222
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
2323
_, _ = w.Write([]byte("hello"))
2424
})
@@ -29,7 +29,7 @@ func TestSimple(t *testing.T) {
2929

3030
// this is our redirect to server
3131
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
32-
req.URL = testutils.ParseURI(srv.URL)
32+
req.URL = testutils.MustParseRequestURI(srv.URL)
3333
fwd.ServeHTTP(w, req)
3434
})
3535

@@ -46,7 +46,7 @@ func TestSimple(t *testing.T) {
4646
assert.Equal(t, "hello", string(body))
4747
}
4848

49-
func TestChunkedEncodingSuccess(t *testing.T) {
49+
func TestBuffer_chunkedEncodingSuccess(t *testing.T) {
5050
var reqBody string
5151
var contentLength int64
5252
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
@@ -63,7 +63,7 @@ func TestChunkedEncodingSuccess(t *testing.T) {
6363

6464
// this is our redirect to server
6565
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
66-
req.URL = testutils.ParseURI(srv.URL)
66+
req.URL = testutils.MustParseRequestURI(srv.URL)
6767
fwd.ServeHTTP(w, req)
6868
})
6969

@@ -74,7 +74,7 @@ func TestChunkedEncodingSuccess(t *testing.T) {
7474
proxy := httptest.NewServer(st)
7575
t.Cleanup(proxy.Close)
7676

77-
conn, err := net.Dial("tcp", testutils.ParseURI(proxy.URL).Host)
77+
conn, err := net.Dial("tcp", testutils.MustParseRequestURI(proxy.URL).Host)
7878
require.NoError(t, err)
7979

8080
_, _ = fmt.Fprintf(conn, "POST / HTTP/1.1\r\nHost: 127.0.0.1:8080\r\nTransfer-Encoding: chunked\r\n\r\n4\r\ntest\r\n5\r\ntest1\r\n5\r\ntest2\r\n0\r\n\r\n")
@@ -86,7 +86,7 @@ func TestChunkedEncodingSuccess(t *testing.T) {
8686
assert.EqualValues(t, len(reqBody), contentLength)
8787
}
8888

89-
func TestChunkedEncodingLimitReached(t *testing.T) {
89+
func TestBuffer_chunkedEncodingLimitReached(t *testing.T) {
9090
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
9191
_, _ = w.Write([]byte("hello"))
9292
})
@@ -97,7 +97,7 @@ func TestChunkedEncodingLimitReached(t *testing.T) {
9797

9898
// this is our redirect to server
9999
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
100-
req.URL = testutils.ParseURI(srv.URL)
100+
req.URL = testutils.MustParseRequestURI(srv.URL)
101101
fwd.ServeHTTP(w, req)
102102
})
103103

@@ -108,7 +108,7 @@ func TestChunkedEncodingLimitReached(t *testing.T) {
108108
proxy := httptest.NewServer(st)
109109
t.Cleanup(proxy.Close)
110110

111-
conn, err := net.Dial("tcp", testutils.ParseURI(proxy.URL).Host)
111+
conn, err := net.Dial("tcp", testutils.MustParseRequestURI(proxy.URL).Host)
112112
require.NoError(t, err)
113113
_, _ = fmt.Fprint(conn, "POST / HTTP/1.1\r\nHost: 127.0.0.1:8080\r\nTransfer-Encoding: chunked\r\n\r\n4\r\ntest\r\n5\r\ntest1\r\n5\r\ntest2\r\n0\r\n\r\n")
114114
status, err := bufio.NewReader(conn).ReadString('\n')
@@ -117,7 +117,7 @@ func TestChunkedEncodingLimitReached(t *testing.T) {
117117
assert.Equal(t, "HTTP/1.1 413 Request Entity Too Large\r\n", status)
118118
}
119119

120-
func TestChunkedResponse(t *testing.T) {
120+
func TestBuffer_chunkedResponse(t *testing.T) {
121121
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
122122
h := w.(http.Hijacker)
123123
conn, _, _ := h.Hijack()
@@ -129,7 +129,7 @@ func TestChunkedResponse(t *testing.T) {
129129
fwd := forward.New(false)
130130

131131
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
132-
req.URL = testutils.ParseURI(srv.URL)
132+
req.URL = testutils.MustParseRequestURI(srv.URL)
133133
fwd.ServeHTTP(w, req)
134134
})
135135
st, err := New(rdr)
@@ -145,7 +145,7 @@ func TestChunkedResponse(t *testing.T) {
145145
assert.Equal(t, strconv.Itoa(len("testtest1test2")), re.Header.Get("Content-Length"))
146146
}
147147

148-
func TestRequestLimitReached(t *testing.T) {
148+
func TestBuffer_requestLimitReached(t *testing.T) {
149149
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
150150
_, _ = w.Write([]byte("hello"))
151151
})
@@ -156,7 +156,7 @@ func TestRequestLimitReached(t *testing.T) {
156156

157157
// this is our redirect to server
158158
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
159-
req.URL = testutils.ParseURI(srv.URL)
159+
req.URL = testutils.MustParseRequestURI(srv.URL)
160160
fwd.ServeHTTP(w, req)
161161
})
162162

@@ -172,7 +172,7 @@ func TestRequestLimitReached(t *testing.T) {
172172
assert.Equal(t, http.StatusRequestEntityTooLarge, re.StatusCode)
173173
}
174174

175-
func TestResponseLimitReached(t *testing.T) {
175+
func TestBuffer_responseLimitReached(t *testing.T) {
176176
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
177177
_, _ = w.Write([]byte("hello, this response is too large"))
178178
})
@@ -183,7 +183,7 @@ func TestResponseLimitReached(t *testing.T) {
183183

184184
// this is our redirect to server
185185
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
186-
req.URL = testutils.ParseURI(srv.URL)
186+
req.URL = testutils.MustParseRequestURI(srv.URL)
187187
fwd.ServeHTTP(w, req)
188188
})
189189

@@ -199,7 +199,7 @@ func TestResponseLimitReached(t *testing.T) {
199199
assert.Equal(t, http.StatusInternalServerError, re.StatusCode)
200200
}
201201

202-
func TestFileStreamingResponse(t *testing.T) {
202+
func TestBuffer_fileStreamingResponse(t *testing.T) {
203203
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
204204
_, _ = w.Write([]byte("hello, this response is too large to fit in memory"))
205205
})
@@ -210,7 +210,7 @@ func TestFileStreamingResponse(t *testing.T) {
210210

211211
// this is our redirect to server
212212
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
213-
req.URL = testutils.ParseURI(srv.URL)
213+
req.URL = testutils.MustParseRequestURI(srv.URL)
214214
fwd.ServeHTTP(w, req)
215215
})
216216

@@ -227,7 +227,7 @@ func TestFileStreamingResponse(t *testing.T) {
227227
assert.Equal(t, "hello, this response is too large to fit in memory", string(body))
228228
}
229229

230-
func TestCustomErrorHandler(t *testing.T) {
230+
func TestBuffer_customErrorHandler(t *testing.T) {
231231
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
232232
_, _ = w.Write([]byte("hello, this response is too large"))
233233
})
@@ -238,7 +238,7 @@ func TestCustomErrorHandler(t *testing.T) {
238238

239239
// this is our redirect to server
240240
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
241-
req.URL = testutils.ParseURI(srv.URL)
241+
req.URL = testutils.MustParseRequestURI(srv.URL)
242242
fwd.ServeHTTP(w, req)
243243
})
244244

@@ -258,7 +258,7 @@ func TestCustomErrorHandler(t *testing.T) {
258258
assert.Equal(t, http.StatusTeapot, re.StatusCode)
259259
}
260260

261-
func TestNotModified(t *testing.T) {
261+
func TestBuffer_notModified(t *testing.T) {
262262
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
263263
w.WriteHeader(http.StatusNotModified)
264264
})
@@ -269,7 +269,7 @@ func TestNotModified(t *testing.T) {
269269

270270
// this is our redirect to server
271271
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
272-
req.URL = testutils.ParseURI(srv.URL)
272+
req.URL = testutils.MustParseRequestURI(srv.URL)
273273
fwd.ServeHTTP(w, req)
274274
})
275275

@@ -285,7 +285,7 @@ func TestNotModified(t *testing.T) {
285285
assert.Equal(t, http.StatusNotModified, re.StatusCode)
286286
}
287287

288-
func TestNoBody(t *testing.T) {
288+
func TestBuffer_noBody(t *testing.T) {
289289
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
290290
w.WriteHeader(http.StatusOK)
291291
})
@@ -296,7 +296,7 @@ func TestNoBody(t *testing.T) {
296296

297297
// this is our redirect to server
298298
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
299-
req.URL = testutils.ParseURI(srv.URL)
299+
req.URL = testutils.MustParseRequestURI(srv.URL)
300300
fwd.ServeHTTP(w, req)
301301
})
302302

@@ -313,7 +313,7 @@ func TestNoBody(t *testing.T) {
313313
}
314314

315315
// Make sure that stream handler preserves TLS settings.
316-
func TestPreservesTLS(t *testing.T) {
316+
func TestBuffer_preservesTLS(t *testing.T) {
317317
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
318318
w.WriteHeader(http.StatusOK)
319319
_, _ = w.Write([]byte("ok"))
@@ -327,7 +327,7 @@ func TestPreservesTLS(t *testing.T) {
327327
// this is our redirect to server
328328
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
329329
cs = req.TLS
330-
req.URL = testutils.ParseURI(srv.URL)
330+
req.URL = testutils.MustParseRequestURI(srv.URL)
331331
fwd.ServeHTTP(w, req)
332332
})
333333

@@ -345,7 +345,7 @@ func TestPreservesTLS(t *testing.T) {
345345
assert.NotNil(t, cs)
346346
}
347347

348-
func TestNotNilBody(t *testing.T) {
348+
func TestBuffer_notNilBody(t *testing.T) {
349349
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
350350
_, _ = w.Write([]byte("hello"))
351351
})
@@ -356,7 +356,7 @@ func TestNotNilBody(t *testing.T) {
356356

357357
// this is our redirect to server
358358
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
359-
req.URL = testutils.ParseURI(srv.URL)
359+
req.URL = testutils.MustParseRequestURI(srv.URL)
360360
// During a request check if the request body is no nil before sending to the next middleware
361361
// Because we can send a POST request without body
362362
assert.NotNil(t, req.Body)
@@ -381,7 +381,7 @@ func TestNotNilBody(t *testing.T) {
381381
assert.Equal(t, "hello", string(body))
382382
}
383383

384-
func TestGRPCErrorResponse(t *testing.T) {
384+
func TestBuffer_GRPC_ErrorResponse(t *testing.T) {
385385
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
386386
w.Header().Set("Grpc-Status", "10" /* ABORTED */)
387387
w.WriteHeader(http.StatusOK)
@@ -396,7 +396,7 @@ func TestGRPCErrorResponse(t *testing.T) {
396396

397397
// this is our redirect to server
398398
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
399-
req.URL = testutils.ParseURI(srv.URL)
399+
req.URL = testutils.MustParseRequestURI(srv.URL)
400400
fwd.ServeHTTP(w, req)
401401
})
402402

@@ -413,7 +413,7 @@ func TestGRPCErrorResponse(t *testing.T) {
413413
assert.Empty(t, body)
414414
}
415415

416-
func TestGRPCOKResponse(t *testing.T) {
416+
func TestBuffer_GRPC_OKResponse(t *testing.T) {
417417
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
418418
w.Header().Set("Grpc-Status", "0" /* OK */)
419419
_, _ = w.Write([]byte("grpc-body"))
@@ -429,7 +429,7 @@ func TestGRPCOKResponse(t *testing.T) {
429429

430430
// this is our redirect to server
431431
rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
432-
req.URL = testutils.ParseURI(srv.URL)
432+
req.URL = testutils.MustParseRequestURI(srv.URL)
433433
fwd.ServeHTTP(w, req)
434434
})
435435

buffer/retry_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/vulcand/oxy/v2/testutils"
1313
)
1414

15-
func TestSuccess(t *testing.T) {
15+
func TestBuffer_success(t *testing.T) {
1616
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
1717
_, _ = w.Write([]byte("hello"))
1818
})
@@ -23,15 +23,15 @@ func TestSuccess(t *testing.T) {
2323
proxy := httptest.NewServer(rt)
2424
t.Cleanup(proxy.Close)
2525

26-
require.NoError(t, lb.UpsertServer(testutils.ParseURI(srv.URL)))
26+
require.NoError(t, lb.UpsertServer(testutils.MustParseRequestURI(srv.URL)))
2727

2828
re, body, err := testutils.Get(proxy.URL)
2929
require.NoError(t, err)
3030
assert.Equal(t, http.StatusOK, re.StatusCode)
3131
assert.Equal(t, "hello", string(body))
3232
}
3333

34-
func TestRetryOnError(t *testing.T) {
34+
func TestBuffer_retryOnError(t *testing.T) {
3535
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
3636
_, _ = w.Write([]byte("hello"))
3737
})
@@ -42,16 +42,16 @@ func TestRetryOnError(t *testing.T) {
4242
proxy := httptest.NewServer(rt)
4343
t.Cleanup(proxy.Close)
4444

45-
require.NoError(t, lb.UpsertServer(testutils.ParseURI("http://localhost:64321")))
46-
require.NoError(t, lb.UpsertServer(testutils.ParseURI(srv.URL)))
45+
require.NoError(t, lb.UpsertServer(testutils.MustParseRequestURI("http://localhost:64321")))
46+
require.NoError(t, lb.UpsertServer(testutils.MustParseRequestURI(srv.URL)))
4747

4848
re, body, err := testutils.Get(proxy.URL, testutils.Body("some request parameters"))
4949
require.NoError(t, err)
5050
assert.Equal(t, http.StatusOK, re.StatusCode)
5151
assert.Equal(t, "hello", string(body))
5252
}
5353

54-
func TestRetryExceedAttempts(t *testing.T) {
54+
func TestBuffer_retryExceedAttempts(t *testing.T) {
5555
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
5656
_, _ = w.Write([]byte("hello"))
5757
})
@@ -62,10 +62,10 @@ func TestRetryExceedAttempts(t *testing.T) {
6262
proxy := httptest.NewServer(rt)
6363
t.Cleanup(proxy.Close)
6464

65-
require.NoError(t, lb.UpsertServer(testutils.ParseURI("http://localhost:64321")))
66-
require.NoError(t, lb.UpsertServer(testutils.ParseURI("http://localhost:64322")))
67-
require.NoError(t, lb.UpsertServer(testutils.ParseURI("http://localhost:64323")))
68-
require.NoError(t, lb.UpsertServer(testutils.ParseURI(srv.URL)))
65+
require.NoError(t, lb.UpsertServer(testutils.MustParseRequestURI("http://localhost:64321")))
66+
require.NoError(t, lb.UpsertServer(testutils.MustParseRequestURI("http://localhost:64322")))
67+
require.NoError(t, lb.UpsertServer(testutils.MustParseRequestURI("http://localhost:64323")))
68+
require.NoError(t, lb.UpsertServer(testutils.MustParseRequestURI(srv.URL)))
6969

7070
re, _, err := testutils.Get(proxy.URL)
7171
require.NoError(t, err)

0 commit comments

Comments
 (0)