This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_job_supervisor.go
91 lines (71 loc) · 1.72 KB
/
fake_job_supervisor.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
package fakes
import (
boshalert "github.com/cloudfoundry/bosh-agent/agent/alert"
boshjobsuper "github.com/cloudfoundry/bosh-agent/jobsupervisor"
)
type FakeJobSupervisor struct {
Reloaded bool
ReloadErr error
AddJobArgs []AddJobArgs
RemovedAllJobs bool
RemovedAllJobsErr error
Started bool
StartErr error
Stopped bool
StopErr error
Unmonitored bool
UnmonitorErr error
StatusStatus string
ProcessesStatus []boshjobsuper.Process
ProcessesError error
JobFailureAlert *boshalert.MonitAlert
}
type AddJobArgs struct {
Name string
Index int
ConfigPath string
}
func NewFakeJobSupervisor() *FakeJobSupervisor {
return &FakeJobSupervisor{}
}
func (m *FakeJobSupervisor) Reload() error {
m.Reloaded = true
return m.ReloadErr
}
func (m *FakeJobSupervisor) AddJob(jobName string, jobIndex int, configPath string) error {
args := AddJobArgs{
Name: jobName,
Index: jobIndex,
ConfigPath: configPath,
}
m.AddJobArgs = append(m.AddJobArgs, args)
return nil
}
func (m *FakeJobSupervisor) RemoveAllJobs() error {
m.RemovedAllJobs = true
return m.RemovedAllJobsErr
}
func (m *FakeJobSupervisor) Start() error {
m.Started = true
return m.StartErr
}
func (m *FakeJobSupervisor) Stop() error {
m.Stopped = true
return m.StopErr
}
func (m *FakeJobSupervisor) Unmonitor() error {
m.Unmonitored = true
return m.UnmonitorErr
}
func (m *FakeJobSupervisor) Status() string {
return m.StatusStatus
}
func (m *FakeJobSupervisor) Processes() ([]boshjobsuper.Process, error) {
return m.ProcessesStatus, m.ProcessesError
}
func (m *FakeJobSupervisor) MonitorJobFailures(handler boshjobsuper.JobFailureHandler) error {
if m.JobFailureAlert != nil {
return handler(*m.JobFailureAlert)
}
return nil
}