This repository has been archived by the owner on Mar 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathmock_job.go
91 lines (68 loc) · 2.02 KB
/
mock_job.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 nomad
import (
"github.com/hashicorp/nomad/api"
"github.com/stretchr/testify/mock"
)
// MockJob is a mock implementation of the Job interface
type MockJob struct {
mock.Mock
}
// Register is a mock implementation of the register interface method
func (m *MockJob) Register(job *api.Job, options *api.WriteOptions) (
*api.JobRegisterResponse,
*api.WriteMeta, error) {
args := m.Called(job, options)
var resp *api.JobRegisterResponse
if r := args.Get(0); r != nil {
resp = r.(*api.JobRegisterResponse)
}
var meta *api.WriteMeta
if r := args.Get(1); r != nil {
meta = r.(*api.WriteMeta)
}
return resp, meta, args.Error(2)
}
// Info returns mock info from the job API
func (m *MockJob) Info(jobID string, q *api.QueryOptions) (*api.Job, *api.QueryMeta, error) {
args := m.Called(jobID, q)
var job *api.Job
if j := args.Get(0); j != nil {
job = j.(*api.Job)
}
var meta *api.QueryMeta
if r := args.Get(1); r != nil {
meta = r.(*api.QueryMeta)
}
return job, meta, args.Error(2)
}
// List returns mock info from the job API
func (m *MockJob) List(q *api.QueryOptions) ([]*api.JobListStub, *api.QueryMeta, error) {
args := m.Called(q)
var jobs []*api.JobListStub
if j := args.Get(0); j != nil {
jobs = j.([]*api.JobListStub)
}
var meta *api.QueryMeta
if r := args.Get(1); r != nil {
meta = r.(*api.QueryMeta)
}
return jobs, meta, args.Error(2)
}
// Deregister is a mock implementation of the interface method
func (m *MockJob) Deregister(jobID string, purge bool, q *api.WriteOptions) (
string, *api.WriteMeta, error) {
args := m.Called(jobID, purge, q)
return "", nil, args.Error(2)
}
func (m *MockJob) Allocations(jobID string, allAllocs bool, q *api.QueryOptions) ([]*api.AllocationListStub, *api.QueryMeta, error) {
args := m.Called(jobID, allAllocs, q)
var allocs []*api.AllocationListStub
if a := args.Get(0); a != nil {
allocs = a.([]*api.AllocationListStub)
}
var meta *api.QueryMeta
if r := args.Get(1); r != nil {
meta = r.(*api.QueryMeta)
}
return allocs, meta, args.Error(2)
}