1
+ // Copyright 2017 The go-ethereum Authors
2
+ // This file is part of the go-ethereum library.
3
+ //
4
+ // The go-ethereum library is free software: you can redistribute it and/or modify
5
+ // it under the terms of the GNU Lesser General Public License as published by
6
+ // the Free Software Foundation, either version 3 of the License, or
7
+ // (at your option) any later version.
8
+ //
9
+ // The go-ethereum library is distributed in the hope that it will be useful,
10
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ // GNU Lesser General Public License for more details.
13
+ //
14
+ // You should have received a copy of the GNU Lesser General Public License
15
+ // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16
+
1
17
package rpc
2
18
3
19
import (
@@ -8,33 +24,31 @@ import (
8
24
)
9
25
10
26
func TestHTTPErrorResponseWithDelete (t * testing.T ) {
11
- httpErrorResponseTest (t , "DELETE" , contentType , "" , http .StatusMethodNotAllowed )
27
+ testHTTPErrorResponse (t , "DELETE" , contentType , "" , http .StatusMethodNotAllowed )
12
28
}
13
29
14
30
func TestHTTPErrorResponseWithPut (t * testing.T ) {
15
- httpErrorResponseTest (t , "PUT" , contentType , "" , http .StatusMethodNotAllowed )
31
+ testHTTPErrorResponse (t , "PUT" , contentType , "" , http .StatusMethodNotAllowed )
16
32
}
17
33
18
34
func TestHTTPErrorResponseWithMaxContentLength (t * testing.T ) {
19
35
body := make ([]rune , maxHTTPRequestContentLength + 1 , maxHTTPRequestContentLength + 1 )
20
- httpErrorResponseTest (t ,
36
+ testHTTPErrorResponse (t ,
21
37
"POST" , contentType , string (body ), http .StatusRequestEntityTooLarge )
22
38
}
23
39
24
40
func TestHTTPErrorResponseWithEmptyContentType (t * testing.T ) {
25
- httpErrorResponseTest (t , "POST" , "" , "" , http .StatusUnsupportedMediaType )
41
+ testHTTPErrorResponse (t , "POST" , "" , "" , http .StatusUnsupportedMediaType )
26
42
}
27
43
28
44
func TestHTTPErrorResponseWithValidRequest (t * testing.T ) {
29
- httpErrorResponseTest (t , "POST" , contentType , "" , 0 )
45
+ testHTTPErrorResponse (t , "POST" , contentType , "" , 0 )
30
46
}
31
47
32
- func httpErrorResponseTest (t * testing.T ,
33
- method , contentType , body string , expectedResponse int ) {
34
-
48
+ func testHTTPErrorResponse (t * testing.T , method , contentType , body string , expected int ) {
35
49
request := httptest .NewRequest (method , "http://url.com" , strings .NewReader (body ))
36
50
request .Header .Set ("content-type" , contentType )
37
- if response , _ := httpErrorResponse (request ); response != expectedResponse {
38
- t .Fatalf ("response code should be %d not %d" , expectedResponse , response )
51
+ if code , _ := validateRequest (request ); code != expected {
52
+ t .Fatalf ("response code should be %d not %d" , expected , code )
39
53
}
40
54
}
0 commit comments