-
Notifications
You must be signed in to change notification settings - Fork 115
/
fake_service.go
52 lines (45 loc) · 1.14 KB
/
fake_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
package fakes
import (
boshtask "github.com/cloudfoundry/bosh-agent/agent/task"
)
type FakeService struct {
StartedTasks map[string]boshtask.Task
CreateTaskErr error
CreateTaskWithIDErr error
}
func NewFakeService() *FakeService {
return &FakeService{
StartedTasks: make(map[string]boshtask.Task),
}
}
func (s *FakeService) CreateTask(
taskFunc boshtask.Func,
cancelFunc boshtask.CancelFunc,
endFunc boshtask.EndFunc,
) (boshtask.Task, error) {
if s.CreateTaskErr != nil {
return boshtask.Task{}, s.CreateTaskErr
}
return s.CreateTaskWithID("fake-generated-task-id", taskFunc, cancelFunc, endFunc), nil
}
func (s *FakeService) CreateTaskWithID(
id string,
taskFunc boshtask.Func,
cancelFunc boshtask.CancelFunc,
endFunc boshtask.EndFunc,
) boshtask.Task {
return boshtask.Task{
ID: id,
State: boshtask.StateRunning,
Func: taskFunc,
CancelFunc: cancelFunc,
EndFunc: endFunc,
}
}
func (s *FakeService) StartTask(task boshtask.Task) {
s.StartedTasks[task.ID] = task
}
func (s *FakeService) FindTaskWithID(id string) (boshtask.Task, bool) {
task, found := s.StartedTasks[id]
return task, found
}