@@ -252,60 +252,49 @@ func TestMoreThanOneParam(t *testing.T) {
252252 compare (t , fullResponse , expectedResponse )
253253}
254254
255- // func TestZeroParams(t *testing.T) {
256- // log.SetOutput(&bytes.Buffer{})
257-
258- // reqString := "\n"
259-
260- // req := httptest.NewRequest("POST",
261- // "http://example.org/query",
262- // strings.NewReader(reqString))
263- // w := httptest.NewRecorder()
264- // queryHandler, err := initQueryHandler(testDbPath,
265- // "SELECT * FROM ip_dns",
266- // 0)
267- // if err != nil {
268- // t.Fatal(err)
269- // }
270- // queryHandler(w, req)
271-
272- // resp := w.Result()
273- // defer resp.Body.Close()
274-
275- // if resp.StatusCode != http.StatusOK {
276- // t.Fatalf(`resp.StatusCode (%d) != http.StatusOK (%d)`, resp.StatusCode, http.StatusOK)
277- // }
278-
279- // if resp.Header.Get("Content-Type") != "application/json" {
280- // t.Fatalf(`resp.Header.Get("Content-Type") (%s) != "application/json"`, resp.Header.Get("Content-Type"))
281- // }
282-
283- // var answer []httpAnswer
284- // decoder := json.NewDecoder(resp.Body)
285- // err = decoder.Decode(&answer)
286- // if err != nil {
287- // t.Fatal(err)
288- // }
289-
290- // expectedResponse := []httpAnswer{
291- // httpAnswer{
292- // Out: [][]interface{}{
293- // []interface{}{"1.1.1.1", "one.one.one.one"},
294- // []interface{}{"8.8.8.8", "google-public-dns-a.google.com"},
295- // []interface{}{"192.30.253.112", "github.com"},
296- // []interface{}{"192.30.253.113", "github.com"},
297- // }},
298- // httpAnswer{
299- // Out: [][]interface{}{
300- // []interface{}{"1.1.1.1", "one.one.one.one"},
301- // []interface{}{"8.8.8.8", "google-public-dns-a.google.com"},
302- // []interface{}{"192.30.253.112", "github.com"},
303- // []interface{}{"192.30.253.113", "github.com"},
304- // }},
305- // }
306-
307- // compare(t, answer, expectedResponse)
308- // }
255+ func TestZeroParams (t * testing.T ) {
256+ log .SetOutput (& bytes.Buffer {})
257+
258+ req := httptest .NewRequest ("GET" ,
259+ "http://example.org/query" ,
260+ nil )
261+ w := httptest .NewRecorder ()
262+ queryHandler , err := initQueryHandler (testDbPath , "SELECT * FROM ip_dns" , 0 )
263+ if err != nil {
264+ t .Fatal (err )
265+ }
266+ queryHandler (w , req )
267+
268+ resp := w .Result ()
269+ defer resp .Body .Close ()
270+
271+ if resp .StatusCode != http .StatusOK {
272+ t .Fatalf (`resp.StatusCode (%d) != http.StatusOK (%d)` , resp .StatusCode , http .StatusOK )
273+ }
274+
275+ if resp .Header .Get ("Content-Type" ) != "application/json" {
276+ t .Fatalf (`resp.Header.Get("Content-Type") (%s) != "application/json"` , resp .Header .Get ("Content-Type" ))
277+ }
278+
279+ var answer []queryResult
280+ decoder := json .NewDecoder (resp .Body )
281+ err = decoder .Decode (& answer )
282+ if err != nil {
283+ t .Fatal (err )
284+ }
285+
286+ expectedResponse := []queryResult {
287+ queryResult {
288+ Out : [][]interface {}{
289+ []interface {}{"1.1.1.1" , "one.one.one.one" },
290+ []interface {}{"8.8.8.8" , "google-public-dns-a.google.com" },
291+ []interface {}{"192.30.253.112" , "github.com" },
292+ []interface {}{"192.30.253.113" , "github.com" },
293+ }},
294+ }
295+
296+ compare (t , answer , expectedResponse )
297+ }
309298
310299func compare (t * testing.T , answer []queryResult , expectedResponse []queryResult ) {
311300 for i , v := range expectedResponse {
@@ -386,7 +375,7 @@ func TestBadPathRequest(t *testing.T) {
386375func TestBadMethodRequest (t * testing.T ) {
387376 log .SetOutput (& bytes.Buffer {})
388377
389- req := httptest .NewRequest ("GET " ,
378+ req := httptest .NewRequest ("PUT " ,
390379 "http://example.org/query" ,
391380 nil )
392381 w := httptest .NewRecorder ()
0 commit comments