go-sample-webpage/pkg/user/user_test.go

31 lines
630 B
Go
Raw Normal View History

2021-11-04 16:58:23 +00:00
package user
import (
"github.com/go-chi/chi/v5"
2021-11-08 01:25:36 +00:00
"github.com/go-chi/jwtauth/v5"
2021-11-04 16:58:23 +00:00
"io"
"net/http/httptest"
"testing"
)
func TestGetLoginForm(t *testing.T) {
req := httptest.NewRequest("GET", "/login", nil)
rec := httptest.NewRecorder()
router := chi.NewRouter()
router.Group(func(r chi.Router) {
2021-11-08 01:25:36 +00:00
tokenAuth := jwtauth.New("HS256", []byte("secret"), nil)
2021-11-09 18:23:19 +00:00
Register(r, tokenAuth, NewConfig())
2021-11-04 16:58:23 +00:00
})
loginForm(rec, req)
_, err := io.ReadAll(rec.Body)
if err != nil {
t.Error("Get login form should not return an error")
}
if rec.Code != 200 {
t.Error("Login form should not return an non 200 status code")
}
}