1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

storage: eliminate mocks, closes #80

This commit is contained in:
James Hillyerd
2018-03-14 21:05:59 -07:00
parent 2cc0da3093
commit 519779b7ba
3 changed files with 16 additions and 193 deletions

View File

@@ -9,12 +9,10 @@ import (
"net/mail"
"time"
"github.com/jhillyerd/enmime"
"github.com/jhillyerd/inbucket/pkg/config"
"github.com/jhillyerd/inbucket/pkg/message"
"github.com/jhillyerd/inbucket/pkg/msghub"
"github.com/jhillyerd/inbucket/pkg/server/web"
"github.com/jhillyerd/inbucket/pkg/storage"
)
type InputMessageData struct {
@@ -26,31 +24,6 @@ type InputMessageData struct {
HTML, Text string
}
func (d *InputMessageData) MockMessage() *storage.MockMessage {
from, _ := mail.ParseAddress(d.From)
to := make([]*mail.Address, len(d.To))
for i, a := range d.To {
to[i], _ = mail.ParseAddress(a)
}
msg := &storage.MockMessage{}
msg.On("ID").Return(d.ID)
msg.On("From").Return(from)
msg.On("To").Return(to)
msg.On("Subject").Return(d.Subject)
msg.On("Date").Return(d.Date)
msg.On("Size").Return(d.Size)
gomsg := &mail.Message{
Header: d.Header,
}
msg.On("ReadHeader").Return(gomsg, nil)
body := &enmime.Envelope{
Text: d.Text,
HTML: d.HTML,
}
msg.On("ReadBody").Return(body, nil)
return msg
}
// isJSONStringEqual is a utility function to return a nicely formatted message when
// comparing a string to a value received from a JSON map.
func isJSONStringEqual(key, expected string, received interface{}) (message string, ok bool) {