1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 01:57:02 +00:00

storage: Message refactoring for #69

- Message interface renamed to StoreMessage
- Message.Delete becomes Store.RemoveMessage
- Added deleted message tracking to Store stub for #80
This commit is contained in:
James Hillyerd
2018-03-11 15:01:40 -07:00
parent 12ad0cb3f0
commit 487e491d6f
11 changed files with 190 additions and 118 deletions

View File

@@ -16,15 +16,21 @@ type MockDataStore struct {
}
// GetMessage mock function
func (m *MockDataStore) GetMessage(name, id string) (Message, error) {
func (m *MockDataStore) GetMessage(name, id string) (StoreMessage, error) {
args := m.Called(name, id)
return args.Get(0).(Message), args.Error(1)
return args.Get(0).(StoreMessage), args.Error(1)
}
// GetMessages mock function
func (m *MockDataStore) GetMessages(name string) ([]Message, error) {
func (m *MockDataStore) GetMessages(name string) ([]StoreMessage, error) {
args := m.Called(name)
return args.Get(0).([]Message), args.Error(1)
return args.Get(0).([]StoreMessage), args.Error(1)
}
// RemoveMessage mock function
func (m *MockDataStore) RemoveMessage(name, id string) error {
args := m.Called(name, id)
return args.Error(0)
}
// PurgeMessages mock function
@@ -39,14 +45,14 @@ func (m *MockDataStore) LockFor(name string) (*sync.RWMutex, error) {
}
// NewMessage temporary for #69
func (m *MockDataStore) NewMessage(mailbox string) (Message, error) {
func (m *MockDataStore) NewMessage(mailbox string) (StoreMessage, error) {
args := m.Called(mailbox)
return args.Get(0).(Message), args.Error(1)
return args.Get(0).(StoreMessage), args.Error(1)
}
// VisitMailboxes accepts a function that will be called with the messages in each mailbox while it
// continues to return true.
func (m *MockDataStore) VisitMailboxes(f func([]Message) (cont bool)) error {
func (m *MockDataStore) VisitMailboxes(f func([]StoreMessage) (cont bool)) error {
return nil
}
@@ -55,6 +61,12 @@ type MockMessage struct {
mock.Mock
}
// Mailbox mock function
func (m *MockMessage) Mailbox() string {
args := m.Called()
return args.String(0)
}
// ID mock function
func (m *MockMessage) ID() string {
args := m.Called()
@@ -127,12 +139,6 @@ func (m *MockMessage) Close() error {
return args.Error(0)
}
// Delete mock function
func (m *MockMessage) Delete() error {
args := m.Called()
return args.Error(0)
}
// String mock function
func (m *MockMessage) String() string {
args := m.Called()