Exemple #1
0
func TestIndexHandler(t *testing.T) {
	setUp()
	req := getGETRequest()
	w := httptest.NewRecorder()
	reg.IndexHandler(buildTestContext("registration_test"), w, req)

	assertCode(t, w, http.StatusOK)
	if w.Body.String() != "[]\n" {
		t.Error(fmt.Printf("Body not ok (%q)\n", w.Body.String()))
	}
}
Exemple #2
0
func TestPOSTIndexHandler(t *testing.T) {
	setUp()
	req := getPOSTRequest(nil)
	w := httptest.NewRecorder()
	reg.IndexHandler(buildTestContext("registration_test"), w, req)

	assertCode(t, w, http.StatusMethodNotAllowed)
	body := getBodyMap(w)
	if body["error"] != "Method not allowed! Use GET" && body["created"] != "" {
		t.Error(fmt.Printf("Body not ok (%q)\n", body))
	}
}
Exemple #3
0
func TestAddingAndReadingRegisteredUser(t *testing.T) {
	setUp()
	req := getPOSTRequest(bytes.NewBuffer([]byte(`{"email":"*****@*****.**"}`)))
	w := httptest.NewRecorder()
	reg.RegisterHandler(buildTestContext("registration_test"), w, req)

	req = getGETRequest()
	w = httptest.NewRecorder()
	reg.IndexHandler(buildTestContext("registration_test"), w, req)

	assertCode(t, w, http.StatusOK)
	var body []map[string]interface{}
	if err := json.Unmarshal([]byte(getBody(w)), &body); err != nil {
		t.Error(err)
	}
	if body[0]["email"] != "*****@*****.**" {
		t.Error(fmt.Printf("Body not ok (%q)\n", body))
	}
}