Loading controllers/isogrids/randomMirror_test.go 0 → 100644 +30 −0 Original line number Diff line number Diff line package isogrids import ( "net/http" "testing" "github.com/taironas/route" tgTesting "github.com/taironas/tinygraphs/testing" ) func TestRandomMirror(t *testing.T) { r := new(route.Router) r.HandleFunc("/isogrids/random-mirror", RandomMirror) test := tgTesting.GenerateHandlerFunc(t, RandomMirror) for _, p := range tgTesting.GoodParams { recorder := test("/isogrids/random-mirror", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } for _, p := range tgTesting.BadParams { recorder := test("/isogrids/random-mirror", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } } controllers/isogrids/random_test.go 0 → 100644 +30 −0 Original line number Diff line number Diff line package isogrids import ( "net/http" "testing" "github.com/taironas/route" tgTesting "github.com/taironas/tinygraphs/testing" ) func TestRandom(t *testing.T) { r := new(route.Router) r.HandleFunc("/isogrids/random", Random) test := tgTesting.GenerateHandlerFunc(t, Random) for _, p := range tgTesting.GoodParams { recorder := test("/isogrids/random", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } for _, p := range tgTesting.BadParams { recorder := test("/isogrids/random", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } } controllers/squares/square.go +0 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ func Square(w http.ResponseWriter, r *http.Request) { e := `"` + theme + key + `"` w.Header().Set("Etag", e) w.Header().Set("Cache-Control", "max-age=2592000") // 30 days if match := r.Header.Get("If-None-Match"); match != "" { if strings.Contains(match, e) { w.WriteHeader(http.StatusNotModified) Loading controllers/squares/square_test.go +20 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package squares import ( "net/http" "net/http/httptest" "testing" "github.com/taironas/route" Loading @@ -18,15 +19,32 @@ func TestSquares(t *testing.T) { for _, p := range tgTesting.GoodParams { recorder := test("/squares/test", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusBadRequest) t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } for _, p := range tgTesting.BadParams { recorder := test("/squares/test", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusBadRequest) t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } // test caching: recorder := test("/squares/cache", "GET", nil, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } if req, err := http.NewRequest("GET", "/squares/cache", nil); err != nil { t.Errorf("%v", err) } else { req.Header.Set("Content-Type", "application/json") req.Header.Set("If-None-Match", recorder.Header().Get("Etag")) recorder2 := httptest.NewRecorder() r.ServeHTTP(recorder2, req) if recorder2.Code != http.StatusNotModified { t.Errorf("returned %v. Expected %v.", recorder2.Code, http.StatusNotModified) } } } Loading
controllers/isogrids/randomMirror_test.go 0 → 100644 +30 −0 Original line number Diff line number Diff line package isogrids import ( "net/http" "testing" "github.com/taironas/route" tgTesting "github.com/taironas/tinygraphs/testing" ) func TestRandomMirror(t *testing.T) { r := new(route.Router) r.HandleFunc("/isogrids/random-mirror", RandomMirror) test := tgTesting.GenerateHandlerFunc(t, RandomMirror) for _, p := range tgTesting.GoodParams { recorder := test("/isogrids/random-mirror", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } for _, p := range tgTesting.BadParams { recorder := test("/isogrids/random-mirror", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } }
controllers/isogrids/random_test.go 0 → 100644 +30 −0 Original line number Diff line number Diff line package isogrids import ( "net/http" "testing" "github.com/taironas/route" tgTesting "github.com/taironas/tinygraphs/testing" ) func TestRandom(t *testing.T) { r := new(route.Router) r.HandleFunc("/isogrids/random", Random) test := tgTesting.GenerateHandlerFunc(t, Random) for _, p := range tgTesting.GoodParams { recorder := test("/isogrids/random", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } for _, p := range tgTesting.BadParams { recorder := test("/isogrids/random", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } }
controllers/squares/square.go +0 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ func Square(w http.ResponseWriter, r *http.Request) { e := `"` + theme + key + `"` w.Header().Set("Etag", e) w.Header().Set("Cache-Control", "max-age=2592000") // 30 days if match := r.Header.Get("If-None-Match"); match != "" { if strings.Contains(match, e) { w.WriteHeader(http.StatusNotModified) Loading
controllers/squares/square_test.go +20 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package squares import ( "net/http" "net/http/httptest" "testing" "github.com/taironas/route" Loading @@ -18,15 +19,32 @@ func TestSquares(t *testing.T) { for _, p := range tgTesting.GoodParams { recorder := test("/squares/test", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusBadRequest) t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } for _, p := range tgTesting.BadParams { recorder := test("/squares/test", "GET", p, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusBadRequest) t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } } // test caching: recorder := test("/squares/cache", "GET", nil, r) if recorder.Code != http.StatusOK { t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK) } if req, err := http.NewRequest("GET", "/squares/cache", nil); err != nil { t.Errorf("%v", err) } else { req.Header.Set("Content-Type", "application/json") req.Header.Set("If-None-Match", recorder.Header().Get("Etag")) recorder2 := httptest.NewRecorder() r.ServeHTTP(recorder2, req) if recorder2.Code != http.StatusNotModified { t.Errorf("returned %v. Expected %v.", recorder2.Code, http.StatusNotModified) } } }