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()) } }
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()) } }