From c8be3709539d4c21309eec0aecb9103376600109 Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Thu, 12 Apr 2018 12:06:43 +0200 Subject: [PATCH] adding test for handler package for simulating multiple requests at once --- app/handlers_test.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/handlers_test.go b/app/handlers_test.go index 2be7d6b9..b947fd9a 100644 --- a/app/handlers_test.go +++ b/app/handlers_test.go @@ -164,8 +164,26 @@ func TestConvertHandler(t *testing.T) { t.Errorf("Handler returned a wrong status code: got '%v' want '%v'", status, http.StatusOK) } - // case 5: sends two requests (almost) simultany. - // TODO + // case 5: sends five requests (almost) simultany. + path, _ = filepath.Abs("../_tests/file.docx") + filesPaths := []string{ + path, + path, + path, + path, + path, + } + + for i := 0; i < len(filesPaths); i++ { + go func(i int) { + req := makeRequest(filesPaths[i]) + rr := httptest.NewRecorder() + h.ServeHTTP(rr, req) + if status := rr.Code; status != http.StatusOK { + t.Errorf("Handler returned a wrong status code: got '%v' want '%v'", status, http.StatusOK) + } + }(i) + } } func TestServeHandler(t *testing.T) {