This repository has been archived by the owner on Mar 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathapi_test.go
104 lines (84 loc) · 2.11 KB
/
api_test.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
package main
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
type mockJobClient struct {
hadoopJobClient
mock.Mock
}
type mockPersistedJobClient struct {
s3JobClient
mock.Mock
}
type mockHdfsJobHistoryClient struct {
hdfsJobHistoryClient
mock.Mock
}
func (m *mockPersistedJobClient) FetchJob(id string) (*job, error) {
args := m.Called(id)
detail := args.Get(0)
if detail != nil {
return args.Get(0).(*job), args.Error(1)
}
return nil, args.Error(1)
}
func (m *mockJobClient) listJobs() (*appsResp, error) {
args := m.Called()
returnVal := args.Get(0)
if returnVal != nil {
return args.Get(0).(*appsResp), args.Error(1)
}
return nil, args.Error(1)
}
func (m *mockJobClient) listFinishedJobs(since time.Time) (*jobsResp, error) {
args := m.Called(since)
returnVal := args.Get(0)
if returnVal != nil {
return args.Get(0).(*jobsResp), args.Error(1)
}
return nil, args.Error(1)
}
func (m *mockJobClient) updateJob(job *job) error {
return nil
}
func (m *mockHdfsJobHistoryClient) updateFromHistoryFile(jt *jobTracker, job *job, full bool) error {
return nil
}
/**
* sets a jobTracker to main.jts
*/
func setJobTracker(client RecentJobClient) *jobTracker {
jts = make(map[string]*jobTracker)
var jt = newJobTracker("foo", "", "", client, &hdfsJobHistoryClient{})
jts["testCluster"] = jt
return jt
}
func TestGetNonExistentJob(t *testing.T) {
id := "nonexistentjob"
mockStorageClient := new(mockPersistedJobClient)
mockStorageClient.On("FetchJob", id).Return(nil, fmt.Errorf("Bad"))
persistedJobClient = mockStorageClient
res := getJob(id)
assert.Nil(t, res)
}
func TestGetJobFromMemory(t *testing.T) {
var id = "job_from_memory"
var job = &job{}
var jt = setJobTracker(new(mockJobClient))
jt.jobs[jobID(id)] = job
res := getJob(id)
assert.Equal(t, res, job)
}
func TestGetJobFromS3(t *testing.T) {
var id = "job_from_s3"
var myjob = &job{}
mockStorageClient := new(mockPersistedJobClient)
mockStorageClient.On("FetchJob", id).Return(myjob, nil)
persistedJobClient = mockStorageClient
res := getJob(id)
assert.Equal(t, myjob, res)
}