-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathhelpers_test.go
44 lines (31 loc) · 1.14 KB
/
helpers_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
40
41
42
43
44
package goweb
import (
"github.com/stretchr/testify/assert"
testhttp "github.com/stretchr/testify/http"
"net/http"
"testing"
)
func TestRedirectTo(t *testing.T) {
r := new(testhttp.TestResponseWriter)
RedirectTo(r, "http://www.stretchr.com", "test")
assert.Equal(t, "http://www.stretchr.com/test", r.Header().Get("Location"))
assert.Equal(t, 0, r.StatusCode)
}
func TestRedirect(t *testing.T) {
r := new(testhttp.TestResponseWriter)
Redirect(r, "http://www.stretchr.com", "test")
assert.Equal(t, "http://www.stretchr.com/test", r.Header().Get("Location"))
assert.Equal(t, http.StatusFound, r.StatusCode)
}
func TestRedirectTemp(t *testing.T) {
r := new(testhttp.TestResponseWriter)
RedirectTemp(r, "http://www.stretchr.com", "test")
assert.Equal(t, "http://www.stretchr.com/test", r.Header().Get("Location"))
assert.Equal(t, http.StatusTemporaryRedirect, r.StatusCode)
}
func TestRedirectPerm(t *testing.T) {
r := new(testhttp.TestResponseWriter)
RedirectPerm(r, "http://www.stretchr.com", "test")
assert.Equal(t, "http://www.stretchr.com/test", r.Header().Get("Location"))
assert.Equal(t, http.StatusMovedPermanently, r.StatusCode)
}