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

Clean up datastore related linter findings

This commit is contained in:
James Hillyerd
2017-12-26 18:54:02 -08:00
parent f62eaa31b9
commit ac21675bd7
3 changed files with 30 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
// Package datastore contains implementation independent datastore logic
package datastore package datastore
import ( import (

View File

@@ -90,9 +90,9 @@ retentionLoop:
dur := time.Minute - since dur := time.Minute - since
log.Tracef("Retention scanner sleeping for %v", dur) log.Tracef("Retention scanner sleeping for %v", dur)
select { select {
case _ = <-rs.globalShutdown: case <-rs.globalShutdown:
break retentionLoop break retentionLoop
case _ = <-time.After(dur): case <-time.After(dur):
} }
} }
// Kickoff scan // Kickoff scan
@@ -102,7 +102,7 @@ retentionLoop:
} }
// Check for global shutdown // Check for global shutdown
select { select {
case _ = <-rs.globalShutdown: case <-rs.globalShutdown:
break retentionLoop break retentionLoop
default: default:
} }
@@ -159,9 +159,7 @@ func (rs *RetentionScanner) doScan() error {
// Join does not retun until the retention scanner has shut down // Join does not retun until the retention scanner has shut down
func (rs *RetentionScanner) Join() { func (rs *RetentionScanner) Join() {
if rs.retentionShutdown != nil { if rs.retentionShutdown != nil {
select { <-rs.retentionShutdown
case <-rs.retentionShutdown:
}
} }
} }

View File

@@ -9,126 +9,148 @@ import (
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
) )
// Mock DataStore object // MockDataStore is a shared mock for unit testing
type MockDataStore struct { type MockDataStore struct {
mock.Mock mock.Mock
} }
// MailboxFor mock function
func (m *MockDataStore) MailboxFor(name string) (Mailbox, error) { func (m *MockDataStore) MailboxFor(name string) (Mailbox, error) {
args := m.Called(name) args := m.Called(name)
return args.Get(0).(Mailbox), args.Error(1) return args.Get(0).(Mailbox), args.Error(1)
} }
// AllMailboxes mock function
func (m *MockDataStore) AllMailboxes() ([]Mailbox, error) { func (m *MockDataStore) AllMailboxes() ([]Mailbox, error) {
args := m.Called() args := m.Called()
return args.Get(0).([]Mailbox), args.Error(1) return args.Get(0).([]Mailbox), args.Error(1)
} }
// Mock Mailbox object // MockMailbox is a shared mock for unit testing
type MockMailbox struct { type MockMailbox struct {
mock.Mock mock.Mock
} }
// GetMessages mock function
func (m *MockMailbox) GetMessages() ([]Message, error) { func (m *MockMailbox) GetMessages() ([]Message, error) {
args := m.Called() args := m.Called()
return args.Get(0).([]Message), args.Error(1) return args.Get(0).([]Message), args.Error(1)
} }
// GetMessage mock function
func (m *MockMailbox) GetMessage(id string) (Message, error) { func (m *MockMailbox) GetMessage(id string) (Message, error) {
args := m.Called(id) args := m.Called(id)
return args.Get(0).(Message), args.Error(1) return args.Get(0).(Message), args.Error(1)
} }
// Purge mock function
func (m *MockMailbox) Purge() error { func (m *MockMailbox) Purge() error {
args := m.Called() args := m.Called()
return args.Error(0) return args.Error(0)
} }
// NewMessage mock function
func (m *MockMailbox) NewMessage() (Message, error) { func (m *MockMailbox) NewMessage() (Message, error) {
args := m.Called() args := m.Called()
return args.Get(0).(Message), args.Error(1) return args.Get(0).(Message), args.Error(1)
} }
// Name mock function
func (m *MockMailbox) Name() string { func (m *MockMailbox) Name() string {
args := m.Called() args := m.Called()
return args.String(0) return args.String(0)
} }
// String mock function
func (m *MockMailbox) String() string { func (m *MockMailbox) String() string {
args := m.Called() args := m.Called()
return args.String(0) return args.String(0)
} }
// Mock Message object // MockMessage is a shared mock for unit testing
type MockMessage struct { type MockMessage struct {
mock.Mock mock.Mock
} }
// ID mock function
func (m *MockMessage) ID() string { func (m *MockMessage) ID() string {
args := m.Called() args := m.Called()
return args.String(0) return args.String(0)
} }
// From mock function
func (m *MockMessage) From() string { func (m *MockMessage) From() string {
args := m.Called() args := m.Called()
return args.String(0) return args.String(0)
} }
// To mock function
func (m *MockMessage) To() []string { func (m *MockMessage) To() []string {
args := m.Called() args := m.Called()
return args.Get(0).([]string) return args.Get(0).([]string)
} }
// Date mock function
func (m *MockMessage) Date() time.Time { func (m *MockMessage) Date() time.Time {
args := m.Called() args := m.Called()
return args.Get(0).(time.Time) return args.Get(0).(time.Time)
} }
// Subject mock function
func (m *MockMessage) Subject() string { func (m *MockMessage) Subject() string {
args := m.Called() args := m.Called()
return args.String(0) return args.String(0)
} }
// ReadHeader mock function
func (m *MockMessage) ReadHeader() (msg *mail.Message, err error) { func (m *MockMessage) ReadHeader() (msg *mail.Message, err error) {
args := m.Called() args := m.Called()
return args.Get(0).(*mail.Message), args.Error(1) return args.Get(0).(*mail.Message), args.Error(1)
} }
// ReadBody mock function
func (m *MockMessage) ReadBody() (body *enmime.Envelope, err error) { func (m *MockMessage) ReadBody() (body *enmime.Envelope, err error) {
args := m.Called() args := m.Called()
return args.Get(0).(*enmime.Envelope), args.Error(1) return args.Get(0).(*enmime.Envelope), args.Error(1)
} }
// ReadRaw mock function
func (m *MockMessage) ReadRaw() (raw *string, err error) { func (m *MockMessage) ReadRaw() (raw *string, err error) {
args := m.Called() args := m.Called()
return args.Get(0).(*string), args.Error(1) return args.Get(0).(*string), args.Error(1)
} }
// RawReader mock function
func (m *MockMessage) RawReader() (reader io.ReadCloser, err error) { func (m *MockMessage) RawReader() (reader io.ReadCloser, err error) {
args := m.Called() args := m.Called()
return args.Get(0).(io.ReadCloser), args.Error(1) return args.Get(0).(io.ReadCloser), args.Error(1)
} }
// Size mock function
func (m *MockMessage) Size() int64 { func (m *MockMessage) Size() int64 {
args := m.Called() args := m.Called()
return int64(args.Int(0)) return int64(args.Int(0))
} }
// Append mock function
func (m *MockMessage) Append(data []byte) error { func (m *MockMessage) Append(data []byte) error {
// []byte arg seems to mess up testify/mock // []byte arg seems to mess up testify/mock
return nil return nil
} }
// Close mock function
func (m *MockMessage) Close() error { func (m *MockMessage) Close() error {
args := m.Called() args := m.Called()
return args.Error(0) return args.Error(0)
} }
// Delete mock function
func (m *MockMessage) Delete() error { func (m *MockMessage) Delete() error {
args := m.Called() args := m.Called()
return args.Error(0) return args.Error(0)
} }
// String mock function
func (m *MockMessage) String() string { func (m *MockMessage) String() string {
args := m.Called() args := m.Called()
return args.String(0) return args.String(0)