go-sample-webpage/pkg/user/user_test.go
kekskurse 7b6204a0b3
All checks were successful
continuous-integration/drone/push Build is passing
Uer Config
2021-11-09 19:23:19 +01:00

30 lines
630 B
Go

package user
import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/jwtauth/v5"
"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) {
tokenAuth := jwtauth.New("HS256", []byte("secret"), nil)
Register(r, tokenAuth, NewConfig())
})
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")
}
}