Skip to content

Commit

Permalink
Refactor guest_links_test.go to use if, got want
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch committed Jan 9, 2025
1 parent 597e734 commit 37151bd
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions handlers/guest_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ func TestGuestLinksPostAcceptsValidRequest(t *testing.T) {
// Copy the ID, which we can't predict in advance.
tt.expected.ID = picoshare.GuestLinkID(response.ID)

if !reflect.DeepEqual(gl, tt.expected) {
t.Fatalf("%s: guest link does not match expected: got %+v, want %+v", tt.description, gl, tt.expected)
if got, want := gl, tt.expected; !reflect.DeepEqual(got, want) {
t.Fatalf("guestLink=%+v, want=%+v", got, want)
}
})
}
Expand Down Expand Up @@ -273,9 +273,8 @@ func TestGuestLinksPostRejectsInvalidRequest(t *testing.T) {
s.Router().ServeHTTP(rec, req)
res := rec.Result()

if status := res.StatusCode; status != http.StatusBadRequest {
t.Fatalf("%s: handler returned wrong status code: got %v want %v",
tt.description, status, http.StatusBadRequest)
if got, want := res.StatusCode, http.StatusBadRequest; got != want {
t.Fatalf("status=%d, want=%d", got, want)
}
})
}
Expand Down Expand Up @@ -308,8 +307,8 @@ func TestDeleteExistingGuestLink(t *testing.T) {
s.Router().ServeHTTP(rec, req)
res := rec.Result()

if status := res.StatusCode; status != http.StatusOK {
t.Fatalf("DELETE returned wrong status code: got %v want %v", status, http.StatusOK)
if got, want := res.StatusCode, http.StatusOK; got != want {
t.Fatalf("status=%d, want=%d", got, want)
}

_, err = dataStore.GetGuestLink(picoshare.GuestLinkID("dummy-guest-link-id"))
Expand All @@ -332,9 +331,8 @@ func TestDeleteNonExistentGuestLink(t *testing.T) {
res := rec.Result()

// File doesn't exist, but there's no error for deleting a non-existent file.
if status := res.StatusCode; status != http.StatusOK {
t.Fatalf("DELETE returned wrong status code: got %v want %v",
status, http.StatusOK)
if got, want := res.StatusCode, http.StatusOK; got != want {
t.Fatalf("status=%d, want=%d", got, want)
}
}

Expand All @@ -351,7 +349,7 @@ func TestDeleteInvalidGuestLink(t *testing.T) {
s.Router().ServeHTTP(rec, req)
res := rec.Result()

if status := res.StatusCode; status != http.StatusBadRequest {
t.Fatalf("DELETE returned wrong status code: got %v want %v", status, http.StatusBadRequest)
if got, want := res.StatusCode, http.StatusBadRequest; got != want {
t.Fatalf("status=%d, want=%d", got, want)
}
}

0 comments on commit 37151bd

Please sign in to comment.