|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - // "net/http" |
| 4 | + "net/http" |
| 5 | + "net/http/httptest" |
5 | 6 | "reflect"
|
6 | 7 | "strconv"
|
7 | 8 | "testing"
|
8 | 9 | )
|
9 | 10 |
|
| 11 | +func TestReverseAggregatorProxyHandler1(t *testing.T) { |
| 12 | + req, err := http.NewRequest("GET", "/recipes", nil) |
| 13 | + if err != nil { |
| 14 | + t.Fatal(err) |
| 15 | + } |
| 16 | + rr := httptest.NewRecorder() |
| 17 | + handler := http.HandlerFunc(ReverseAggregatorProxyHandler) |
| 18 | + handler.ServeHTTP(rr, req) |
| 19 | + if status := rr.Code; status != http.StatusOK { |
| 20 | + t.Errorf("Status code: got %v want %v", |
| 21 | + status, http.StatusOK) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +func TestAllRecipeHandler1(t *testing.T) { |
| 26 | + req, err := http.NewRequest("GET", "/recipes?top=10&skip=-5", nil) |
| 27 | + if err != nil { |
| 28 | + t.Fatal(err) |
| 29 | + } |
| 30 | + rr := httptest.NewRecorder() |
| 31 | + handler := http.HandlerFunc(ReverseAggregatorProxyHandler) |
| 32 | + handler.ServeHTTP(rr, req) |
| 33 | + if status := rr.Code; status != http.StatusOK { |
| 34 | + t.Errorf("Status code: got %v want %v", |
| 35 | + status, http.StatusOK) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +func TestAggregatedRecipeHandler2(t *testing.T) { |
| 40 | + req, err := http.NewRequest("GET", "/recipes?ids=1,2,3a,-4", nil) |
| 41 | + if err != nil { |
| 42 | + t.Fatal(err) |
| 43 | + } |
| 44 | + rr := httptest.NewRecorder() |
| 45 | + handler := http.HandlerFunc(ReverseAggregatorProxyHandler) |
| 46 | + handler.ServeHTTP(rr, req) |
| 47 | + if status := rr.Code; status != http.StatusOK { |
| 48 | + t.Errorf("Status code: got %v want %v", |
| 49 | + status, http.StatusOK) |
| 50 | + } |
| 51 | +} |
| 52 | + |
10 | 53 | func TestFilter(t *testing.T) {
|
11 | 54 | type args struct {
|
12 | 55 | input []string
|
|
0 commit comments