Esempio n. 1
0
func TestDelete(t *testing.T) {
	mb, err := mailbox.Create("delete")
	if err != nil {
		t.Fatal(err)
	}

	msg, err := mb.PutMessage("TEST")
	if err != nil {
		t.Fatal(err)
	}

	key := mailbox.AccessKey{MailboxId: mb.Id}
	key.Create()
	req := api.DeleteMessageRequest{Message: msg.Id}
	req.Sign(key.Name, key.Secret)
	resp := api.DeleteMessageResponse{}

	statusCode := doRequest(t, req, &resp, "delete")
	if statusCode != 200 {
		t.Fatal("Server responded with", statusCode)
	}

	count, err := mb.MessageCount()
	if err != nil {
		t.Fatal(err)
	}

	if count != 0 {
		t.Fatal("Message count should be 0 but is", count)
	}
}
Esempio n. 2
0
// Delete removes a message from the server. This is generally called after a
// message has been successfully processed to remove it from the mailbox queue.
func (client *Client) Delete(msgId string) (*api.DeleteMessageResponse, error) {
	request := api.DeleteMessageRequest{Message: msgId}
	request.Sign(client.AccessKeyName, client.AccessKey)
	var response api.DeleteMessageResponse
	err := client.request("delete", request, &response)
	if err != nil {
		return nil, err
	}
	if !response.Validate(client.AccessKey) {
		return nil, errors.New("Could not validate signature")
	}
	return &response, nil
}