@@ -17,13 +17,15 @@ func TestEcho(t *testing.T) {
1717 method string
1818 path string
1919 headers map [string ]string
20+ parameters []string
21+ queries map [string ]string
2022 body interface {}
2123 expectedStatus int
2224 }{
2325 {
2426 name : "GET request with no parameters" ,
2527 method : "GET" ,
26- path : "/echo " ,
28+ path : "/" ,
2729 expectedStatus : http .StatusOK ,
2830 },
2931 {
@@ -39,11 +41,31 @@ func TestEcho(t *testing.T) {
3941 expectedStatus : http .StatusOK ,
4042 },
4143 {
42- name : "GET request with query parameters" ,
44+ name : "GET request with query parameters" ,
45+ method : "GET" ,
46+ path : "/echo?param1=value1¶m2=value2" ,
47+ queries : map [string ]string {
48+ "param1" : "value1" ,
49+ "param2" : "value2" ,
50+ },
51+ expectedStatus : http .StatusOK ,
52+ },
53+ {
54+ name : "GET request with path parameters" ,
4355 method : "GET" ,
44- path : "/echo?param1=value1¶m2=value2" ,
56+ path : "/echo/param1/param2" ,
57+ parameters : []string {"param1" , "param2" },
4558 expectedStatus : http .StatusOK ,
4659 },
60+ {
61+ name : "GET request with custom status code" ,
62+ method : "GET" ,
63+ path : "/?status=404" ,
64+ queries : map [string ]string {
65+ "status" : "404" ,
66+ },
67+ expectedStatus : http .StatusNotFound ,
68+ },
4769 }
4870
4971 for _ , tt := range tests {
@@ -68,16 +90,25 @@ func TestEcho(t *testing.T) {
6890 assert .Equal (t , tt .expectedStatus , resp .StatusCode )
6991 assert .Equal (t , "application/json" , resp .Header .Get ("Content-Type" ))
7092 assert .NotEmpty (t , resp .Header .Get (httpHeaderAppName ))
71- assert .NotEmpty (t , resp .Header .Get (httpHeaderAppVersion ))
72- assert .NotEmpty (t , resp .Header .Get (httpHeaderAppBuild ))
7393
7494 var response EchoResponse
7595 err := json .NewDecoder (resp .Body ).Decode (& response )
7696 assert .NoError (t , err )
7797
7898 assert .NotEmpty (t , response .HostInfo .Hostname )
7999 assert .NotEmpty (t , response .HostInfo .IP )
80- assert .NotEmpty (t , response .HttpInfo .Headers )
100+
101+ if tt .headers != nil {
102+ assert .NotEmpty (t , response .HttpInfo .Headers )
103+ }
104+
105+ if tt .parameters != nil {
106+ assert .NotEmpty (t , response .HttpInfo .Params )
107+ }
108+
109+ if tt .queries != nil {
110+ assert .NotEmpty (t , response .HttpInfo .Queries )
111+ }
81112
82113 if tt .body != nil {
83114 assert .NotNil (t , response .HttpInfo .Body )
@@ -103,7 +134,7 @@ func TestMapHeaders(t *testing.T) {
103134}
104135
105136func TestMapQuery (t * testing.T ) {
106- url := "http://example.com?param1=value1¶m2 =value2"
137+ url := "http://example.com?param1=value1¶m2 =value2"
107138 req , _ := http .NewRequest ("GET" , url , nil )
108139
109140 result := mapQuery (req .URL .Query ())
@@ -135,9 +166,9 @@ func TestMapBody(t *testing.T) {
135166 },
136167 },
137168 {
138- name : "invalid JSON body" ,
139- body : "invalid json " ,
140- expected : nil ,
169+ name : "text body" ,
170+ body : "valid text " ,
171+ expected : "valid text" ,
141172 },
142173 }
143174
0 commit comments