test: add test to complete
This commit is contained in:
parent
fa89b17ca9
commit
db45430982
@ -11,6 +11,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
@ -84,4 +85,26 @@ func Test_create(t *testing.T) {
|
|||||||
var info meta.Request
|
var info meta.Request
|
||||||
err := json.Unmarshal(res.Body.Bytes(), &info)
|
err := json.Unmarshal(res.Body.Bytes(), &info)
|
||||||
assert.NoError(t, err)
|
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())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user