mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
rest: Implement MarkSeen for #58
- message: Add MarkSeen to Manager, StoreManager. - rest: Add PATCH for /mailbox/name/id. - rest: Add MailboxMarkSeenV1 handler. - rest: Add Seen to model. - rest: Update handlers to set Seen. - rest: Add doJSONBody func.
This commit is contained in:
@@ -35,17 +35,29 @@ func (m *mockHTTPClient) Do(req *http.Request) (resp *http.Response, err error)
|
||||
StatusCode: m.statusCode,
|
||||
Body: ioutil.NopCloser(bytes.NewBufferString(m.body)),
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (m *mockHTTPClient) ReqBody() []byte {
|
||||
r, err := m.req.GetBody()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
body, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
_ = r.Close()
|
||||
return body
|
||||
}
|
||||
|
||||
func TestDo(t *testing.T) {
|
||||
var want, got string
|
||||
|
||||
mth := &mockHTTPClient{}
|
||||
c := &restClient{mth, baseURL}
|
||||
body := []byte("Test body")
|
||||
|
||||
_, err := c.do("POST", "/dopost")
|
||||
_, err := c.do("POST", "/dopost", body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -61,6 +73,11 @@ func TestDo(t *testing.T) {
|
||||
if got != want {
|
||||
t.Errorf("req.URL == %q, want %q", got, want)
|
||||
}
|
||||
|
||||
b := mth.ReqBody()
|
||||
if !bytes.Equal(b, body) {
|
||||
t.Errorf("req.Body == %q, want %q", b, body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDoJSON(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user