Exemple #1
0
func TestGetAndRender404(t *testing.T) {
	wrc = NewWrc(t)

	jpg404 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		http.NotFound(w, r)
	}))
	defer jpg404.Close()

	shield.ComputeEngineHost = jpg404.URL
	if err := shield.GetAndRender(MagicRequest, wrc.c, wrc.w, wrc.r); err != nil {
		t.Fatal(err)
	}
	if wrc.w.Code != 404 {
		t.Fatal("expected 404, got", wrc.w.Code)
	}
	defer wrc.c.Close()
}
Exemple #2
0
func TestGetAndRender200(t *testing.T) {
	wrc = NewWrc(t)

	jpg200 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/jpeg")
		fmt.Fprint(w, MagicResponse)
	}))
	defer jpg200.Close()

	shield.ComputeEngineHost = jpg200.URL
	if err := shield.GetAndRender(MagicRequest, wrc.c, wrc.w, wrc.r); err != nil {
		t.Fatal(err)
	}
	if wrc.w.Code != 200 {
		t.Fatal("expected 200, got", wrc.w.Code)
	}
	if wrc.w.Body.String() != MagicResponse {
		t.Fatal("expected "+MagicResponse+" , got ", wrc.w.Body.String())
	}
	defer wrc.c.Close()
}