1
1
package static
2
2
3
3
import (
4
+ "context"
4
5
"io/ioutil"
5
6
"net/http"
6
7
"net/http/httptest"
@@ -13,8 +14,14 @@ import (
13
14
"github.com/stretchr/testify/assert"
14
15
)
15
16
17
+ << << << < HEAD:serve_test .go
16
18
func PerformRequest (r http.Handler , method , path string ) * httptest.ResponseRecorder {
17
19
req , _ := http .NewRequest (method , path , nil )
20
+ == == == =
21
+ // nolint:unparam
22
+ func performRequest (r http.Handler , method , path string ) * httptest.ResponseRecorder {
23
+ req , _ := http .NewRequestWithContext (context .Background (), method , path , nil )
24
+ >> >> >> > 7756450 (chore (lint ): add golang lint config ):static_test .go
18
25
w := httptest .NewRecorder ()
19
26
r .ServeHTTP (w , req )
20
27
return w
@@ -36,13 +43,13 @@ func TestEmptyDirectory(t *testing.T) {
36
43
router := gin .New ()
37
44
router .Use (ServeRoot ("/" , dir ))
38
45
router .GET ("/" , func (c * gin.Context ) {
39
- c .String (200 , "index" )
46
+ c .String (http . StatusOK , "index" )
40
47
})
41
48
router .GET ("/a" , func (c * gin.Context ) {
42
- c .String (200 , "a" )
49
+ c .String (http . StatusOK , "a" )
43
50
})
44
51
router .GET ("/" + filename , func (c * gin.Context ) {
45
- c .String (200 , "this is not printed" )
52
+ c .String (http . StatusOK , "this is not printed" )
46
53
})
47
54
w := PerformRequest (router , "GET" , "/" )
48
55
assert .Equal (t , w .Code , 200 )
@@ -62,7 +69,7 @@ func TestEmptyDirectory(t *testing.T) {
62
69
router2 := gin .New ()
63
70
router2 .Use (ServeRoot ("/static" , dir ))
64
71
router2 .GET ("/" + filename , func (c * gin.Context ) {
65
- c .String (200 , "this is printed" )
72
+ c .String (http . StatusOK , "this is printed" )
66
73
})
67
74
68
75
w = PerformRequest (router2 , "GET" , "/" )
@@ -71,7 +78,7 @@ func TestEmptyDirectory(t *testing.T) {
71
78
w = PerformRequest (router2 , "GET" , "/static" )
72
79
assert .Equal (t , w .Code , 404 )
73
80
router2 .GET ("/static" , func (c * gin.Context ) {
74
- c .String (200 , "index" )
81
+ c .String (http . StatusOK , "index" )
75
82
})
76
83
77
84
w = PerformRequest (router2 , "GET" , "/static" )
0 commit comments