From db45430982ce585bfbd9fa45c6b13c697e870bc3 Mon Sep 17 00:00:00 2001 From: Alexander Baryshnikov Date: Thu, 17 Sep 2020 20:18:31 +0800 Subject: [PATCH] test: add test to complete --- server/server_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/server_test.go b/server/server_test.go index 7df7d62..65b18b6 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -11,6 +11,7 @@ import ( "os" "path/filepath" "testing" + "time" "github.com/stretchr/testify/assert" @@ -84,4 +85,26 @@ func Test_create(t *testing.T) { var info meta.Request err := json.Unmarshal(res.Body.Bytes(), &info) assert.NoError(t, err) + + // wait for result + var resultLocation string + for { + req = httptest.NewRequest(http.MethodGet, infoURL+"/completed", nil) + res = httptest.NewRecorder() + srv.ServeHTTP(res, req) + if res.Code == http.StatusMovedPermanently { + resultLocation = res.Header().Get("Location") + break + } + if assert.Equal(t, http.StatusNotFound, res.Code) { + return + } + time.Sleep(time.Second) + } + + req = httptest.NewRequest(http.MethodGet, resultLocation, nil) + res = httptest.NewRecorder() + srv.ServeHTTP(res, req) + assert.Equal(t, http.StatusOK, res.Code) + assert.Equal(t, "hello world", res.Body.String()) }