-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathreverse_handler_test.go
More file actions
38 lines (31 loc) · 882 Bytes
/
reverse_handler_test.go
File metadata and controls
38 lines (31 loc) · 882 Bytes
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
package mps
import (
"io"
"net/http"
"net/http/httptest"
"net/url"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewReverseHandler(t *testing.T) {
srv := newTestServer()
defer srv.Close()
reverseHandler := NewReverseHandler()
proxySrv := httptest.NewServer(reverseHandler)
defer proxySrv.Close()
resp, err := HttpGet(srv.URL, func(r *http.Request) (*url.URL, error) {
return url.Parse(proxySrv.URL)
})
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
bodySize := len(body)
contentLength, _ := strconv.Atoi(resp.Header.Get("Content-Length"))
asserts := assert.New(t)
asserts.Equal(resp.StatusCode, 200, "statusCode should be equal 200")
asserts.Equal(bodySize, contentLength, "Content-Length should be equal "+strconv.Itoa(bodySize))
asserts.Equal(int64(bodySize), resp.ContentLength)
}