Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: scheduler/appengine/apiservers/scheduler_test.go

Issue 2945843002: scheduler WIP: add GetAllJobs api. (Closed)
Patch Set: meh Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « scheduler/appengine/apiservers/scheduler.go ('k') | scheduler/appengine/presentation/doc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package apiservers
6
7 import (
8 "testing"
9
10 "golang.org/x/net/context"
11
12 "github.com/golang/protobuf/proto"
13 "github.com/luci/luci-go/appengine/gaetesting"
14 "github.com/luci/luci-go/server/auth/identity"
15
16 scheduler "github.com/luci/luci-go/scheduler/api/scheduler/v1"
17 "github.com/luci/luci-go/scheduler/appengine/catalog"
18 "github.com/luci/luci-go/scheduler/appengine/engine"
19 "github.com/luci/luci-go/scheduler/appengine/messages"
20 "github.com/luci/luci-go/scheduler/appengine/task/urlfetch"
21
22 . "github.com/smartystreets/goconvey/convey"
23 )
24
25 func TestGetJobsApi(t *testing.T) {
26 t.Parallel()
27
28 Convey("Scheduler GetJobs API works", t, func() {
29 ctx := gaetesting.TestingContext()
30 fakeEng, catalog := newTestEngine()
31 So(catalog.RegisterTaskManager(&urlfetch.TaskManager{}), ShouldB eNil)
32
33 ss := SchedulerServer{fakeEng, catalog}
34 taskBlob, err := proto.Marshal(&messages.TaskDefWrapper{
35 UrlFetch: &messages.UrlFetchTask{Url: "http://example.co m/path"},
36 })
37 So(err, ShouldBeNil)
38
39 Convey("Empty", func() {
40 fakeEng.getAllJobs = func() ([]*engine.Job, error) { ret urn []*engine.Job{}, nil }
41 reply, err := ss.GetJobs(ctx, nil)
42 So(err, ShouldBeNil)
43 So(len(reply.GetJobs()), ShouldEqual, 0)
44 })
45
46 Convey("All Projects", func() {
47 fakeEng.getAllJobs = func() ([]*engine.Job, error) {
48 return []*engine.Job{
49 {
50 JobID: "foo",
51 ProjectID: "bar",
52 Schedule: "0 * * * * * *",
53 State: engine.JobState{State : engine.JobStateRunning},
54 Task: taskBlob,
55 },
56 {
57 JobID: "faz",
58 Paused: true,
59 ProjectID: "baz",
60 Schedule: "with 1m interval",
61 State: engine.JobState{State : engine.JobStateSuspended},
62 Task: taskBlob,
63 },
64 }, nil
65 }
66 reply, err := ss.GetJobs(ctx, nil)
67 So(err, ShouldBeNil)
68 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{
69 {
70 Id: "foo",
71 Project: "bar",
72 Schedule: "0 * * * * * *",
73 State: &scheduler.JobState{UiStatus: "RUNNING"},
74 },
75 {
76 Id: "faz",
77 Project: "baz",
78 Schedule: "with 1m interval",
79 State: &scheduler.JobState{UiStatus: "PAUSED"},
80 },
81 })
82 })
83
84 Convey("One Project", func() {
85 fakeEng.getProjectJobs = func(projectID string) ([]*engi ne.Job, error) {
86 So(projectID, ShouldEqual, "bar")
87 return []*engine.Job{
88 {
89 JobID: "foo",
90 ProjectID: "bar",
91 Schedule: "0 * * * * * *",
92 State: engine.JobState{State : engine.JobStateRunning},
93 Task: taskBlob,
94 },
95 }, nil
96 }
97 reply, err := ss.GetJobs(ctx, &scheduler.JobsRequest{Pro ject: "bar"})
98 So(err, ShouldBeNil)
99 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{
100 {
101 Id: "foo",
102 Project: "bar",
103 Schedule: "0 * * * * * *",
104 State: &scheduler.JobState{UiStatus: "RUNNING"},
105 },
106 })
107 })
108 })
109 }
110
111 ////
112
113 func newTestEngine() (*fakeEngine, catalog.Catalog) {
114 cat := catalog.New("scheduler.cfg")
115 return &fakeEngine{}, cat
116 }
117
118 type fakeEngine struct {
119 getAllJobs func() ([]*engine.Job, error)
120 getProjectJobs func(projectID string) ([]*engine.Job, error)
121 }
122
123 func (f *fakeEngine) GetAllProjects(c context.Context) ([]string, error) {
124 panic("not implemented")
125 }
126
127 func (f *fakeEngine) GetAllJobs(c context.Context) ([]*engine.Job, error) {
128 return f.getAllJobs()
129 }
130
131 func (f *fakeEngine) GetProjectJobs(c context.Context, projectID string) ([]*eng ine.Job, error) {
132 return f.getProjectJobs(projectID)
133 }
134
135 func (f *fakeEngine) GetJob(c context.Context, jobID string) (*engine.Job, error ) {
136 panic("not implemented")
137 }
138
139 func (f *fakeEngine) ListInvocations(c context.Context, jobID string, pageSize i nt, cursor string) ([]*engine.Invocation, string, error) {
140 panic("not implemented")
141 }
142
143 func (f *fakeEngine) GetInvocation(c context.Context, jobID string, invID int64) (*engine.Invocation, error) {
144 panic("not implemented")
145 }
146
147 func (f *fakeEngine) GetInvocationsByNonce(c context.Context, invNonce int64) ([ ]*engine.Invocation, error) {
148 panic("not implemented")
149 }
150
151 func (f *fakeEngine) UpdateProjectJobs(c context.Context, projectID string, defs []catalog.Definition) error {
152 panic("not implemented")
153 }
154
155 func (f *fakeEngine) ResetAllJobsOnDevServer(c context.Context) error {
156 panic("not implemented")
157 }
158
159 func (f *fakeEngine) ExecuteSerializedAction(c context.Context, body []byte, ret ryCount int) error {
160 panic("not implemented")
161 }
162
163 func (f *fakeEngine) ProcessPubSubPush(c context.Context, body []byte) error {
164 panic("not implemented")
165 }
166
167 func (f *fakeEngine) PullPubSubOnDevServer(c context.Context, taskManagerName st ring, publisher string) error {
168 panic("not implemented")
169 }
170
171 func (f *fakeEngine) TriggerInvocation(c context.Context, jobID string, triggere dBy identity.Identity) (int64, error) {
172 panic("not implemented")
173 }
174
175 func (f *fakeEngine) PauseJob(c context.Context, jobID string, who identity.Iden tity) error {
176 panic("not implemented")
177 }
178
179 func (f *fakeEngine) ResumeJob(c context.Context, jobID string, who identity.Ide ntity) error {
180 panic("not implemented")
181 }
182
183 func (f *fakeEngine) AbortInvocation(c context.Context, jobID string, invID int6 4, who identity.Identity) error {
184 panic("not implemented")
185 }
186
187 func (f *fakeEngine) AbortJob(c context.Context, jobID string, who identity.Iden tity) error {
188 panic("not implemented")
189 }
OLDNEW
« no previous file with comments | « scheduler/appengine/apiservers/scheduler.go ('k') | scheduler/appengine/presentation/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698