| OLD | NEW |
| (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 context "golang.org/x/net/context" |
| 11 |
| 12 "github.com/luci/luci-go/appengine/gaetesting" |
| 13 "github.com/luci/luci-go/server/auth/identity" |
| 14 |
| 15 scheduler "github.com/luci/luci-go/scheduler/api/scheduler/v1" |
| 16 "github.com/luci/luci-go/scheduler/appengine/catalog" |
| 17 "github.com/luci/luci-go/scheduler/appengine/engine" |
| 18 |
| 19 . "github.com/smartystreets/goconvey/convey" |
| 20 ) |
| 21 |
| 22 func TestGetJobsApi(t *testing.T) { |
| 23 t.Parallel() |
| 24 |
| 25 Convey("Scheduler GetJobs API works", t, func() { |
| 26 ctx := gaetesting.TestingContext() |
| 27 fakeEng, catalog := newTestEngine() |
| 28 ss := SchedulerServer{fakeEng, catalog} |
| 29 |
| 30 Convey("Empty", func() { |
| 31 fakeEng.getAllJobs = func() ([]*engine.Job, error) { ret
urn []*engine.Job{}, nil } |
| 32 reply, err := ss.GetJobs(ctx, nil) |
| 33 So(err, ShouldBeNil) |
| 34 So(len(reply.GetJobs()), ShouldEqual, 0) |
| 35 }) |
| 36 |
| 37 Convey("All Projects", func() { |
| 38 fakeEng.getAllJobs = func() ([]*engine.Job, error) { |
| 39 return []*engine.Job{ |
| 40 { |
| 41 JobID: "foo", |
| 42 ProjectID: "bar", |
| 43 Schedule: "0 * * * * * *", |
| 44 State: engine.JobState{State
: engine.JobStateRunning}, |
| 45 }, |
| 46 { |
| 47 JobID: "faz", |
| 48 ProjectID: "baz", |
| 49 Schedule: "with 1m interval", |
| 50 Paused: true, |
| 51 State: engine.JobState{State
: engine.JobStateSuspended}, |
| 52 }, |
| 53 }, nil |
| 54 } |
| 55 reply, err := ss.GetJobs(ctx, nil) |
| 56 So(err, ShouldBeNil) |
| 57 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{ |
| 58 { |
| 59 Id: "foo", |
| 60 Project: "bar", |
| 61 Schedule: "0 * * * * * *", |
| 62 State: &scheduler.JobState{UiStatus:
"RUNNING"}, |
| 63 }, |
| 64 { |
| 65 Id: "faz", |
| 66 Project: "baz", |
| 67 Schedule: "with 1m interval", |
| 68 State: &scheduler.JobState{UiStatus:
"PAUSED"}, |
| 69 }, |
| 70 }) |
| 71 }) |
| 72 |
| 73 Convey("One Project", func() { |
| 74 fakeEng.getProjectJobs = func(projectID string) ([]*engi
ne.Job, error) { |
| 75 So(projectID, ShouldEqual, "bar") |
| 76 return []*engine.Job{ |
| 77 { |
| 78 JobID: "foo", |
| 79 ProjectID: "bar", |
| 80 Schedule: "0 * * * * * *", |
| 81 State: engine.JobState{State
: engine.JobStateRunning}, |
| 82 }, |
| 83 }, nil |
| 84 } |
| 85 reply, err := ss.GetJobs(ctx, &scheduler.JobsRequest{Pro
ject: "bar"}) |
| 86 So(err, ShouldBeNil) |
| 87 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{ |
| 88 { |
| 89 Id: "foo", |
| 90 Project: "bar", |
| 91 Schedule: "0 * * * * * *", |
| 92 State: &scheduler.JobState{UiStatus:
"RUNNING"}, |
| 93 }, |
| 94 }) |
| 95 }) |
| 96 }) |
| 97 } |
| 98 |
| 99 //// |
| 100 |
| 101 func newTestEngine() (*fakeEngine, catalog.Catalog) { |
| 102 cat := catalog.New("scheduler.cfg") |
| 103 return &fakeEngine{}, cat |
| 104 } |
| 105 |
| 106 type fakeEngine struct { |
| 107 getAllJobs func() ([]*engine.Job, error) |
| 108 getProjectJobs func(projectID string) ([]*engine.Job, error) |
| 109 } |
| 110 |
| 111 func (f *fakeEngine) GetAllProjects(c context.Context) ([]string, error) { |
| 112 panic("not implemented") |
| 113 } |
| 114 |
| 115 func (f *fakeEngine) GetAllJobs(c context.Context) ([]*engine.Job, error) { |
| 116 return f.getAllJobs() |
| 117 } |
| 118 |
| 119 func (f *fakeEngine) GetProjectJobs(c context.Context, projectID string) ([]*eng
ine.Job, error) { |
| 120 return f.getProjectJobs(projectID) |
| 121 } |
| 122 |
| 123 func (f *fakeEngine) GetJob(c context.Context, jobID string) (*engine.Job, error
) { |
| 124 panic("not implemented") |
| 125 } |
| 126 |
| 127 func (f *fakeEngine) ListInvocations(c context.Context, jobID string, pageSize i
nt, cursor string) ([]*engine.Invocation, string, error) { |
| 128 panic("not implemented") |
| 129 } |
| 130 |
| 131 func (f *fakeEngine) GetInvocation(c context.Context, jobID string, invID int64)
(*engine.Invocation, error) { |
| 132 panic("not implemented") |
| 133 } |
| 134 |
| 135 func (f *fakeEngine) GetInvocationsByNonce(c context.Context, invNonce int64) ([
]*engine.Invocation, error) { |
| 136 panic("not implemented") |
| 137 } |
| 138 |
| 139 func (f *fakeEngine) UpdateProjectJobs(c context.Context, projectID string, defs
[]catalog.Definition) error { |
| 140 panic("not implemented") |
| 141 } |
| 142 |
| 143 func (f *fakeEngine) ResetAllJobsOnDevServer(c context.Context) error { |
| 144 panic("not implemented") |
| 145 } |
| 146 |
| 147 func (f *fakeEngine) ExecuteSerializedAction(c context.Context, body []byte, ret
ryCount int) error { |
| 148 panic("not implemented") |
| 149 } |
| 150 |
| 151 func (f *fakeEngine) ProcessPubSubPush(c context.Context, body []byte) error { |
| 152 panic("not implemented") |
| 153 } |
| 154 |
| 155 func (f *fakeEngine) PullPubSubOnDevServer(c context.Context, taskManagerName st
ring, publisher string) error { |
| 156 panic("not implemented") |
| 157 } |
| 158 |
| 159 func (f *fakeEngine) TriggerInvocation(c context.Context, jobID string, triggere
dBy identity.Identity) (int64, error) { |
| 160 panic("not implemented") |
| 161 } |
| 162 |
| 163 func (f *fakeEngine) PauseJob(c context.Context, jobID string, who identity.Iden
tity) error { |
| 164 panic("not implemented") |
| 165 } |
| 166 |
| 167 func (f *fakeEngine) ResumeJob(c context.Context, jobID string, who identity.Ide
ntity) error { |
| 168 panic("not implemented") |
| 169 } |
| 170 |
| 171 func (f *fakeEngine) AbortInvocation(c context.Context, jobID string, invID int6
4, who identity.Identity) error { |
| 172 panic("not implemented") |
| 173 } |
| 174 |
| 175 func (f *fakeEngine) AbortJob(c context.Context, jobID string, who identity.Iden
tity) error { |
| 176 panic("not implemented") |
| 177 } |
| OLD | NEW |