Skip to content

Commit 39b833c

Browse files
elboulangerojbkempf
authored andcommitted
logs: Add another unit test
1 parent fe4ec13 commit 39b833c

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

logs/logs_test.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func TestLogDownload(t *testing.T) {
260260

261261
buf.Reset()
262262

263-
/* */
263+
/* Test a log line with 200 status code */
264264
p := &mirrors.Results{
265265
FileInfo: filesystem.FileInfo{
266266
Path: "/test/file.tgz",
@@ -294,7 +294,7 @@ func TestLogDownload(t *testing.T) {
294294

295295
buf.Reset()
296296

297-
/* */
297+
/* Test a log line with 404 status code */
298298
p = &mirrors.Results{
299299
FileInfo: filesystem.FileInfo{
300300
Path: "/test/file.tgz",
@@ -311,7 +311,7 @@ func TestLogDownload(t *testing.T) {
311311

312312
buf.Reset()
313313

314-
/* */
314+
/* Test a log line with 500 status code */
315315
p = &mirrors.Results{
316316
MirrorList: mirrors.Mirrors{
317317
mirrors.Mirror{
@@ -334,7 +334,7 @@ func TestLogDownload(t *testing.T) {
334334

335335
buf.Reset()
336336

337-
/* */
337+
/* Test a log line with 501 status code */
338338
p = &mirrors.Results{
339339
FileInfo: filesystem.FileInfo{
340340
Path: "/test/file.tgz",
@@ -350,4 +350,21 @@ func TestLogDownload(t *testing.T) {
350350
}
351351

352352
buf.Reset()
353+
354+
/* Make sure we don't trip when there's a %s (aka a "verb") in the request */
355+
p = &mirrors.Results{
356+
FileInfo: filesystem.FileInfo{
357+
Path: "/test/%s/hacked",
358+
},
359+
IP: "192.168.0.1",
360+
}
361+
362+
LogDownload("JSON", "GET", 404, p, nil)
363+
364+
expected = "JSON 404 GET \"/test/%s/hacked\" ip:192.168.0.1\n"
365+
if !strings.HasSuffix(buf.String(), expected) {
366+
t.Fatalf("Invalid log line:\nGot:\n%#vs\nExpected:\n%#v", buf.String(), expected)
367+
}
368+
369+
buf.Reset()
353370
}

0 commit comments

Comments
 (0)