Exemple #1
0
func TestCreateSession(t *testing.T) {
	db := NewTestDB()
	defer db.Close()

	hash, _ := bcrypt.GenerateFromPassword([]byte("password"), cost)
	db.Exec(`INSERT INTO users (email, password) VALUES('*****@*****.**', $1)`, string(hash))

	for _, test := range createSessionTestData {
		w := httptest.NewRecorder()
		r, _ := http.NewRequest("POST", test.path, bytes.NewBufferString(test.body))

		auth.Mux(db).ServeHTTP(w, r)

		eq(t, test.expCode, w.Code)
		eq(t, test.expBody, w.Body.String())
	}
}
Exemple #2
0
func TestGetCurrentUser(t *testing.T) {
	db := NewTestDB()
	defer db.Close()

	hash, _ := bcrypt.GenerateFromPassword([]byte("password"), cost)
	db.Exec(`INSERT INTO users(email, password, token) VALUES('*****@*****.**', $1, $2)`, string(hash), createToken("*****@*****.**"))

	for _, test := range getCurrentUserTestData {
		w := httptest.NewRecorder()
		r, _ := http.NewRequest("GET", test.path, nil)
		for k, v := range test.headers {
			r.Header.Set(k, v)
		}

		auth.Mux(db).ServeHTTP(w, r)

		eq(t, test.expCode, w.Code)
		eq(t, test.expBody, w.Body.String())
	}
}