File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import (
11
11
"time"
12
12
13
13
"github.com/stretchr/testify/assert"
14
+ "net/http/httptest"
14
15
)
15
16
16
17
func testRequest (t * testing.T , url string ) {
@@ -103,3 +104,28 @@ func TestBadUnixSocket(t *testing.T) {
103
104
router := New ()
104
105
assert .Error (t , router .RunUnix ("#/tmp/unix_unit_test" ))
105
106
}
107
+
108
+ func TestWithHttptestWithAutoSelectedPort (t * testing.T ) {
109
+ router := New ()
110
+ router .GET ("/example" , func (c * Context ) { c .String (http .StatusOK , "it worked" ) })
111
+
112
+ ts := httptest .NewServer (router )
113
+ defer ts .Close ()
114
+
115
+ testRequest (t , ts .URL + "/example" )
116
+ }
117
+
118
+ func TestWithHttptestWithSpecifiedPort (t * testing.T ) {
119
+ router := New ()
120
+ router .GET ("/example" , func (c * Context ) { c .String (http .StatusOK , "it worked" ) })
121
+
122
+ l , _ := net .Listen ("tcp" , ":8033" )
123
+ ts := httptest.Server {
124
+ Listener : l ,
125
+ Config : & http.Server {Handler : router },
126
+ }
127
+ ts .Start ()
128
+ defer ts .Close ()
129
+
130
+ testRequest (t , "http://localhost:8033/example" )
131
+ }
You can’t perform that action at this time.
0 commit comments