-
Notifications
You must be signed in to change notification settings - Fork 1
/
http_server_handle_resize_test.go
39 lines (31 loc) · 1.29 KB
/
http_server_handle_resize_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package httpserver
import (
"log"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/valyala/fasthttp"
"github.com/xaionaro-go/unsafetools"
)
func TestHTTPServerHandleResize(t *testing.T) {
logger := log.New(os.Stderr, ``, 0)
srv, err := NewHTTPServer(&dummyImageProcessor{}, logger, logger)
assert.NoError(t, err)
checkRequest := func(expectedStatusCode int, uri string) {
ctx := &fasthttp.RequestCtx{}
*unsafetools.FieldByName(ctx, `s`).(**fasthttp.Server) = srv.httpBackend
ctx.Request.SetRequestURI(uri)
srv.httpRouter.Handler(ctx)
assert.Equal(t, expectedStatusCode, ctx.Response.StatusCode(), string(ctx.Response.Body()))
}
checkRequest(200, `/resize?width=100&height=100&url=test_picture`)
checkRequest(400, `/resize?height=100&url=test_picture`)
checkRequest(400, `/resize?width=100&url=test_picture`)
checkRequest(400, `/resize?width=100&height=100`)
checkRequest(400, `/resize?width=0&height=100&url=test_picture`)
checkRequest(400, `/resize?width=-100&height=100&url=test_picture`)
checkRequest(400, `/resize?width=100000&height=100&url=test_picture`)
checkRequest(400, `/resize?width=100&height=0&url=test_picture`)
checkRequest(400, `/resize?width=100&height=-100&url=test_picture`)
checkRequest(502, `/resize?width=100&height=100&url=htttp://invalid_url/`)
}