1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-11-28 08:58:38 +02:00
authboss/defaults/values_test.go
Aaron L 386133a84b Add a way to read values and validate
In order to support multiple different types of requests, there needed
to be an interface to be able to read values from a request, and
subsequently validate them to return any errors.

So we've adjusted the Validator interface to no longer validate a
request but instead validate the object it lives on.

And we've created a new BodyReader interface.
2018-02-04 18:39:25 -08:00

29 lines
576 B
Go

package defaults
import (
"testing"
"github.com/volatiletech/authboss"
"github.com/volatiletech/authboss/internal/mocks"
)
func TestHTTPFormReader(t *testing.T) {
t.Parallel()
h := NewHTTPFormReader(false)
r := mocks.Request("POST", "email", "john@john.john", "password", "flowers")
validator, err := h.Read("login", r)
if err != nil {
t.Error(err)
}
uv := validator.(authboss.UserValuer)
if "john@john.john" != uv.GetPID() {
t.Error("wrong e-mail:", uv.GetPID())
}
if "flowers" != uv.GetPassword() {
t.Error("wrong password:", uv.GetPassword())
}
}