github.com/volatiletech/authboss@v2.4.1+incompatible/defaults/renderer_test.go (about) 1 package defaults 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/volatiletech/authboss" 8 ) 9 10 func TestJSONRenderer(t *testing.T) { 11 t.Parallel() 12 13 r := JSONRenderer{} 14 15 success := authboss.HTMLData{"fun": "times"} 16 failure := authboss.HTMLData{authboss.DataErr: "problem"} 17 hasAlready := authboss.HTMLData{authboss.DataErr: "problem", "status": "noproblem"} 18 19 b, _, err := r.Render(context.Background(), "", success) 20 if err != nil { 21 t.Error(err) 22 } 23 if string(b) != `{"fun":"times","status":"success"}` { 24 t.Errorf("wrong json: %s", b) 25 } 26 27 b, _, err = r.Render(context.Background(), "", failure) 28 if err != nil { 29 t.Error(err) 30 } 31 if string(b) != `{"error":"problem","status":"failure"}` { 32 t.Errorf("wrong json: %s", b) 33 } 34 35 b, _, err = r.Render(context.Background(), "", hasAlready) 36 if err != nil { 37 t.Error(err) 38 } 39 if string(b) != `{"error":"problem","status":"noproblem"}` { 40 t.Errorf("wrong json: %s", b) 41 } 42 }