dm
/
vain
forked from sm/vain
1
0
Fork 0

Better error reporting

Change-Id: I36dc5ad3648c5b4ac2cc2c72ba90fec7398090bf
This commit is contained in:
Stephen McQuay 2016-06-21 07:54:00 -07:00
parent 639d82ac7b
commit 45c0af4d1e
No known key found for this signature in database
GPG Key ID: 1ABF428F71BAFC3D
2 changed files with 49 additions and 7 deletions

View File

@ -631,16 +631,28 @@ func TestRoundTrip(t *testing.T) {
u := fmt.Sprintf("%s%s?email=fake@example.com", ts.URL, prefix["register"])
req, err := http.NewRequest("POST", u, nil)
_, err = http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("couldn't POST: %v", err)
}
req, err = http.NewRequest("GET", mm.msg, nil)
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("couldn't POST: %v", err)
}
if got, want := resp.StatusCode, http.StatusOK; got != want {
buf := &bytes.Buffer{}
io.Copy(buf, resp.Body)
t.Logf("%s", buf.Bytes())
t.Fatalf("bad request got incorrect status: got %d, want %d", got, want)
}
req, err = http.NewRequest("GET", mm.msg, nil)
resp, err = http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("couldn't POST: %v", err)
}
if got, want := resp.StatusCode, http.StatusOK; got != want {
buf := &bytes.Buffer{}
io.Copy(buf, resp.Body)
t.Logf("%s", buf.Bytes())
t.Fatalf("bad request got incorrect status: got %d, want %d", got, want)
}
_, err = db.user("fake@example.com")
if err != nil {
@ -661,6 +673,12 @@ func TestRoundTrip(t *testing.T) {
if err != nil {
t.Fatalf("couldn't POST: %v", err)
}
if got, want := resp.StatusCode, http.StatusOK; got != want {
buf := &bytes.Buffer{}
io.Copy(buf, resp.Body)
t.Logf("%s", buf.Bytes())
t.Fatalf("bad request got incorrect status: got %d, want %d", got, want)
}
if got, want := len(db.Pkgs()), 1; got != want {
t.Fatalf("pkgs should have something in it; got %d, want %d", got, want)
@ -687,6 +705,9 @@ func TestForgot(t *testing.T) {
t.Fatalf("couldn't POST: %v", err)
}
if status := resp.StatusCode; status != http.StatusNotFound {
buf := &bytes.Buffer{}
io.Copy(buf, resp.Body)
t.Logf("%s", buf.Bytes())
t.Fatalf("handler returned wrong status code: got %v want %v",
status, http.StatusBadRequest)
}
@ -698,6 +719,9 @@ func TestForgot(t *testing.T) {
t.Fatalf("couldn't POST: %v", err)
}
if status := resp.StatusCode; status != http.StatusBadRequest {
buf := &bytes.Buffer{}
io.Copy(buf, resp.Body)
t.Logf("%s", buf.Bytes())
t.Fatalf("handler returned wrong status code: got %v want %v",
status, http.StatusBadRequest)
}
@ -714,6 +738,12 @@ func TestForgot(t *testing.T) {
if err != nil {
t.Fatalf("couldn't POST: %v", err)
}
if got, want := resp.StatusCode, http.StatusOK; got != want {
buf := &bytes.Buffer{}
io.Copy(buf, resp.Body)
t.Logf("%s", buf.Bytes())
t.Fatalf("bad request got incorrect status: got %d, want %d", got, want)
}
//check database for new user
_, err = db.user("fake@example.com")
@ -738,6 +768,12 @@ func TestForgot(t *testing.T) {
if err != nil {
t.Fatalf("couldn't POST: %v", err)
}
if got, want := resp.StatusCode, http.StatusOK; got != want {
buf := &bytes.Buffer{}
io.Copy(buf, resp.Body)
t.Logf("%s", buf.Bytes())
t.Fatalf("bad request got incorrect status: got %d, want %d", got, want)
}
ft, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatalf("Failed to parse response body: %v", err)
@ -758,6 +794,12 @@ func TestForgot(t *testing.T) {
if err != nil {
t.Fatalf("couldn't POST: %v", err)
}
if got, want := resp.StatusCode, http.StatusOK; got != want {
buf := &bytes.Buffer{}
io.Copy(buf, resp.Body)
t.Logf("%s", buf.Bytes())
t.Fatalf("bad request got incorrect status: got %d, want %d", got, want)
}
if got, want := len(db.Pkgs()), 1; got != want {
t.Fatalf("pkgs should have something in it; got %d, want %d", got, want)
}

2
db.go
View File

@ -259,7 +259,7 @@ func (db *DB) Confirm(token string) (string, error) {
)
if err != nil {
return "", verrors.HTTP{
Message: fmt.Sprintf("couldn't update user with token %q", token),
Message: fmt.Sprintf("couldn't update user with token %q: %v", token, err),
Code: http.StatusInternalServerError,
}
}