Skip to content

Commit

Permalink
chore(allsrv): add test for the delete foo API
Browse files Browse the repository at this point in the history
This test currently fails, but it's not entirely obvious as to why. Fix
the bug and make these tests pass.
  • Loading branch information
jsteenb2 committed Jul 5, 2024
1 parent 1e34905 commit 6a573b2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions allsrv/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ func TestServer(t *testing.T) {
assert.Equal(t, http.StatusOK, rec.Code)
})
})

t.Run("foo delete", func(t *testing.T) {
t.Run("when deleting an existing foo should pass", func(t *testing.T) {
db := new(allsrv.InmemDB)
err := db.CreateFoo(allsrv.Foo{
ID: "id1",
Name: "first_name",
Note: "first note",
})
require.NoError(t, err)

svr := allsrv.NewServer(db, "dodgers@stink.com", "PaSsWoRd")

req := httptest.NewRequest("DELETE", "/foo?id=id1", nil)
req.SetBasicAuth("dodgers@stink.com", "PaSsWoRd")
rec := httptest.NewRecorder()

svr.ServeHTTP(rec, req)

assert.Equal(t, http.StatusOK, rec.Code)
})
})
}

func newJSONBody(t *testing.T, v any) *bytes.Buffer {
Expand Down

0 comments on commit 6a573b2

Please sign in to comment.