@@ -1680,6 +1680,32 @@ func TestContextAbortWithStatusJSON(t *testing.T) {
16801680 assert .JSONEq (t , "{\" foo\" :\" fooValue\" ,\" bar\" :\" barValue\" }" , jsonStringBody )
16811681}
16821682
1683+ func TestContextAbortWithStatusPureJSON (t * testing.T ) {
1684+ w := httptest .NewRecorder ()
1685+ c , _ := CreateTestContext (w )
1686+ c .index = 4
1687+
1688+ in := new (testJSONAbortMsg )
1689+ in .Bar = "barValue"
1690+ in .Foo = "fooValue"
1691+
1692+ c .AbortWithStatusPureJSON (http .StatusUnsupportedMediaType , in )
1693+
1694+ assert .Equal (t , abortIndex , c .index )
1695+ assert .Equal (t , http .StatusUnsupportedMediaType , c .Writer .Status ())
1696+ assert .Equal (t , http .StatusUnsupportedMediaType , w .Code )
1697+ assert .True (t , c .IsAborted ())
1698+
1699+ contentType := w .Header ().Get ("Content-Type" )
1700+ assert .Equal (t , "application/json; charset=utf-8" , contentType )
1701+
1702+ buf := new (bytes.Buffer )
1703+ _ , err := buf .ReadFrom (w .Body )
1704+ require .NoError (t , err )
1705+ jsonStringBody := buf .String ()
1706+ assert .JSONEq (t , "{\" foo\" :\" fooValue\" ,\" bar\" :\" barValue\" }" , jsonStringBody )
1707+ }
1708+
16831709func TestContextError (t * testing.T ) {
16841710 c , _ := CreateTestContext (httptest .NewRecorder ())
16851711 assert .Empty (t , c .Errors )
0 commit comments