2017-04-03 23:52:41 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIndexViewHandler(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := map[string]struct {
|
|
|
|
expectedStatusCode int
|
|
|
|
expectedBodyContains string
|
|
|
|
}{
|
|
|
|
"success": {
|
|
|
|
expectedStatusCode: http.StatusPermanentRedirect,
|
|
|
|
expectedBodyContains: "Redirect",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
2017-04-07 08:59:24 +02:00
|
|
|
req, err := http.NewRequest(http.MethodGet, "/", nil)
|
2017-04-03 23:52:41 +02:00
|
|
|
assert.NoError(err)
|
|
|
|
|
|
|
|
rr := httptest.NewRecorder()
|
|
|
|
handler := IndexViewHandler()
|
|
|
|
|
|
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
|
|
|
|
assert.Equal(tc.expectedStatusCode, rr.Code)
|
|
|
|
assert.Contains(rr.Body.String(), tc.expectedBodyContains)
|
|
|
|
}
|
|
|
|
}
|