-
Notifications
You must be signed in to change notification settings - Fork 3
/
mock_service.go
110 lines (98 loc) · 2.68 KB
/
mock_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package recurring
import (
"context"
"time"
"github.com/lloydmeta/tasques/internal/domain/metadata"
"github.com/lloydmeta/tasques/internal/domain/task"
)
var MockNow = time.Now().UTC()
type MockRecurringTasksService struct {
CreateCalled uint
CreateOverride func() (*Task, error)
GetCalled uint
GetOverride func() (*Task, error)
UpdateCalled uint
UpdateOverride func() (*Task, error)
DeleteCalled uint
DeleteOverride func() (*Task, error)
AllCalled uint
AllOverride func() ([]Task, error)
MarkLoadedCalled uint
MarkLoadedOverride func() (*MultiUpdateResult, error)
NotLoadedCalled uint
NotLoadedOverride func() ([]Task, error)
}
var MockDomainRecurringTask = Task{
ID: "mock",
ScheduleExpression: "* * * * *",
TaskDefinition: TaskDefinition{
Queue: "q",
Kind: "k",
},
IsDeleted: false,
LoadedAt: nil,
Metadata: metadata.Metadata{
CreatedAt: metadata.CreatedAt(MockNow),
ModifiedAt: metadata.ModifiedAt(MockNow),
Version: metadata.Version{
SeqNum: 0,
PrimaryTerm: 1,
},
},
}
func (m *MockRecurringTasksService) Create(ctx context.Context, task *NewTask) (*Task, error) {
m.CreateCalled++
if m.CreateOverride != nil {
return m.CreateOverride()
} else {
return &MockDomainRecurringTask, nil
}
}
func (m *MockRecurringTasksService) Get(ctx context.Context, id task.RecurringTaskId, includeSoftDeleted bool) (*Task, error) {
m.GetCalled++
if m.GetOverride != nil {
return m.GetOverride()
} else {
return &MockDomainRecurringTask, nil
}
}
func (m *MockRecurringTasksService) Delete(ctx context.Context, id task.RecurringTaskId) (*Task, error) {
m.DeleteCalled++
if m.DeleteOverride != nil {
return m.DeleteOverride()
} else {
return &MockDomainRecurringTask, nil
}
}
func (m *MockRecurringTasksService) All(ctx context.Context) ([]Task, error) {
m.AllCalled++
if m.AllOverride != nil {
return m.AllOverride()
} else {
return []Task{MockDomainRecurringTask}, nil
}
}
func (m *MockRecurringTasksService) Update(ctx context.Context, update *Task) (*Task, error) {
m.UpdateCalled++
if m.UpdateOverride != nil {
return m.UpdateOverride()
} else {
return &MockDomainRecurringTask, nil
}
}
func (m *MockRecurringTasksService) MarkLoaded(ctx context.Context, toMarks []Task) (*MultiUpdateResult, error) {
m.MarkLoadedCalled++
if m.MarkLoadedOverride != nil {
return m.MarkLoadedOverride()
} else {
return &MultiUpdateResult{}, nil
}
}
func (m *MockRecurringTasksService) NotLoaded(ctx context.Context) ([]Task, error) {
m.NotLoadedCalled++
if m.NotLoadedOverride != nil {
return m.NotLoadedOverride()
} else {
return []Task{MockDomainRecurringTask}, nil
}
}