This repository has been archived by the owner on Feb 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
mock.go
98 lines (79 loc) · 1.84 KB
/
mock.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
package scheduler
import (
"fmt"
"github.com/rakanalh/scheduler/storage"
)
type failureMode int
const (
fail failureMode = iota
failOnLastRun
failOnNextRun
failOnDuration
failOnIsRecurring
failOnFuncMeta
failOnEmptyParams
failOnEmptyListParams
)
type storeMock struct {
Mode failureMode
}
func newStoreMockWithMode(mode failureMode) *storeMock {
return &storeMock{
Mode: mode,
}
}
func (s *storeMock) Add(task storage.TaskAttributes) error {
return nil
}
func (s *storeMock) Fetch() ([]storage.TaskAttributes, error) {
if s.Mode == fail {
return []storage.TaskAttributes{}, fmt.Errorf("Error")
}
taskAttributes := storage.TaskAttributes{
Hash: "TestHash",
}
if s.Mode == failOnLastRun {
taskAttributes.LastRun = "SomeCorruptString"
} else {
taskAttributes.LastRun = "2017-11-10T12:00:00Z"
}
if s.Mode == failOnNextRun {
taskAttributes.NextRun = "SomeCorruptString"
} else {
taskAttributes.NextRun = "2017-11-10T12:00:00Z"
}
if s.Mode == failOnDuration {
taskAttributes.Duration = "SomeCorruptString"
} else {
taskAttributes.Duration = "5s"
}
if s.Mode == failOnIsRecurring {
taskAttributes.IsRecurring = "SomeCorruptString"
} else {
taskAttributes.IsRecurring = "1"
}
if s.Mode == failOnFuncMeta {
taskAttributes.Name = "NonExistentName"
} else {
taskAttributes.Name = "github.com/rakanalh/scheduler.mockFunction"
}
if s.Mode == failOnEmptyParams {
taskAttributes.Params = ""
} else {
taskAttributes.Params = "[]"
}
if s.Mode == failOnEmptyListParams {
taskAttributes.Params = "SomeCorruptString"
} else if s.Mode != failOnEmptyParams {
taskAttributes.Params = "[]"
}
return []storage.TaskAttributes{taskAttributes}, nil
}
func (s *storeMock) Remove(task storage.TaskAttributes) error {
return nil
}
func (s *storeMock) Close() error {
return nil
}
func mockFunction(a string, b int) {
}