@@ -862,6 +862,56 @@ func TestCheckResponse(t *testing.T) {
862862 }
863863}
864864
865+ func TestCheckResponse_RateLimit (t * testing.T ) {
866+ res := & http.Response {
867+ Request : & http.Request {},
868+ StatusCode : http .StatusForbidden ,
869+ Header : http.Header {},
870+ Body : ioutil .NopCloser (strings .NewReader (`{"message":"m",
871+ "documentation_url": "url"}` )),
872+ }
873+ res .Header .Set (headerRateLimit , "60" )
874+ res .Header .Set (headerRateRemaining , "0" )
875+ res .Header .Set (headerRateReset , "243424" )
876+
877+ err := CheckResponse (res ).(* RateLimitError )
878+
879+ if err == nil {
880+ t .Errorf ("Expected error response." )
881+ }
882+
883+ want := & RateLimitError {
884+ Rate : parseRate (res ),
885+ Response : res ,
886+ Message : "m" ,
887+ }
888+ if ! reflect .DeepEqual (err , want ) {
889+ t .Errorf ("Error = %#v, want %#v" , err , want )
890+ }
891+ }
892+
893+ func TestCheckResponse_AbuseRateLimit (t * testing.T ) {
894+ res := & http.Response {
895+ Request : & http.Request {},
896+ StatusCode : http .StatusForbidden ,
897+ Body : ioutil .NopCloser (strings .NewReader (`{"message":"m",
898+ "documentation_url": "developer.github.com/v3/#abuse-rate-limits"}` )),
899+ }
900+ err := CheckResponse (res ).(* AbuseRateLimitError )
901+
902+ if err == nil {
903+ t .Errorf ("Expected error response." )
904+ }
905+
906+ want := & AbuseRateLimitError {
907+ Response : res ,
908+ Message : "m" ,
909+ }
910+ if ! reflect .DeepEqual (err , want ) {
911+ t .Errorf ("Error = %#v, want %#v" , err , want )
912+ }
913+ }
914+
865915// ensure that we properly handle API errors that do not contain a response body
866916func TestCheckResponse_noBody (t * testing.T ) {
867917 res := & http.Response {
0 commit comments