Esempio n. 1
0
func TestSpaceInvadersCache(t *testing.T) {
	t.Parallel()
	r := new(route.Router)
	r.HandleFunc("/spaceinvaders/:key", SpaceInvaders)
	var etag string
	test := tgTesting.GenerateHandlerFunc(t, SpaceInvaders)

	if recorder := test("/spaceinvaders/somekey", "GET", nil, r); recorder != nil {
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
		etag = recorder.Header().Get("Etag")
	}

	// test caching
	if req, err := http.NewRequest("GET", "/spaceinvaders/somekey", nil); err != nil {
		t.Errorf("%v", err)
	} else {
		req.Header.Set("If-None-Match", etag)
		recorder := httptest.NewRecorder()
		r.ServeHTTP(recorder, req)
		if recorder.Code != http.StatusNotModified {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusNotModified)
		}
	}
}
Esempio n. 2
0
func TestHexa16(t *testing.T) {
	t.Parallel()
	r := new(route.Router)
	r.HandleFunc("/isogrids/labs/hexa16", Hexa)
	r.HandleFunc("/isogrids/labs/hexa16/:key", Hexa)

	test := tgTesting.GenerateHandlerFunc(t, Hexa)
	for _, p := range tgTesting.GoodParams {
		recorder := test("/isogrids/labs/hexa16", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
		recorder = test("/isogrids/labs/hexa16/somekey", "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/labs/hexa16", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
		recorder = test("/isogrids/labs/hexa16/somekey", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}

	}
}
Esempio n. 3
0
func TestTheme(t *testing.T) {
	t.Parallel()
	r := new(route.Router)
	r.HandleFunc("/themes", Theme)
	r.HandleFunc("/themes/:key", Theme)

	test := tgTesting.GenerateHandlerFunc(t, Theme)
	for _, p := range tgTesting.GoodParams {
		recorder := test("/themes", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
		recorder = test("/themes/somekey", "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("/themes", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
		recorder = test("/themes/somekey", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
	}
}
Esempio n. 4
0
func TestBannerRandomGradient(t *testing.T) {
	t.Parallel()
	r := new(route.Router)
	r.HandleFunc("/isogrids/banner/random/gradient", BannerRandomGradient)

	test := tgTesting.GenerateHandlerFunc(t, BannerRandomGradient)
	for _, p := range tgTesting.GoodParams {
		recorder := test("/isogrids/banner/random/gradient", "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/banner/random/gradient", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
	}
}
Esempio n. 5
0
func TestRandom(t *testing.T) {
	t.Parallel()
	r := new(route.Router)
	r.HandleFunc("/squares/random", Random)

	test := tgTesting.GenerateHandlerFunc(t, Random)
	for _, p := range tgTesting.GoodParams {
		recorder := test("/squares/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("/squares/random", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
	}
}
Esempio n. 6
0
func TestIsogrids(t *testing.T) {
	t.Parallel()
	r := new(route.Router)
	r.HandleFunc("/isogrids/:key", Isogrids)

	test := tgTesting.GenerateHandlerFunc(t, Isogrids)
	for _, p := range tgTesting.GoodParams {
		recorder := test("/isogrids/test", "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/test", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
	}
}
Esempio n. 7
0
func TestCheckerboard(t *testing.T) {
	t.Parallel()
	r := new(route.Router)
	r.HandleFunc("/checkerboard", Checkerboard)

	test := tgTesting.GenerateHandlerFunc(t, Checkerboard)
	for _, p := range tgTesting.GoodParams {
		recorder := test("/checkerboard", "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("/checkerboard", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
	}

}
Esempio n. 8
0
func TestSquares(t *testing.T) {
	t.Parallel()
	r := new(route.Router)
	r.HandleFunc("/squares/:key", Square)

	test := tgTesting.GenerateHandlerFunc(t, Square)
	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.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.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)
		}
	}
}