1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-11-24 08:42:17 +02:00
authboss/defaults/renderer_test.go

43 lines
922 B
Go

package defaults
import (
"context"
"testing"
"github.com/volatiletech/authboss"
)
func TestJSONRenderer(t *testing.T) {
t.Parallel()
r := JSONRenderer{}
success := authboss.HTMLData{"fun": "times"}
failure := authboss.HTMLData{authboss.DataErr: "problem"}
hasAlready := authboss.HTMLData{authboss.DataErr: "problem", "status": "noproblem"}
b, _, err := r.Render(context.Background(), "", success)
if err != nil {
t.Error(err)
}
if string(b) != `{"fun":"times","status":"success"}` {
t.Errorf("wrong json: %s", b)
}
b, _, err = r.Render(context.Background(), "", failure)
if err != nil {
t.Error(err)
}
if string(b) != `{"error":"problem","status":"failure"}` {
t.Errorf("wrong json: %s", b)
}
b, _, err = r.Render(context.Background(), "", hasAlready)
if err != nil {
t.Error(err)
}
if string(b) != `{"error":"problem","status":"noproblem"}` {
t.Errorf("wrong json: %s", b)
}
}