| 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 State: engine.JobState{State
: engine.JobStateSuspended}, |
| 51 }, |
| 52 }, nil |
| 53 } |
| 54 reply, err := ss.GetJobs(ctx, nil) |
| 55 So(err, ShouldBeNil) |
| 56 So(reply.GetJobs(), ShouldResemble, []*scheduler.JobWith
State{ |
| 57 { |
| 58 Id: "foo", |
| 59 Project: "bar", |
| 60 Schedule: "0 * * * * * *", |
| 61 State: &scheduler.JobState{Kind: "RUN
NING"}, |
| 62 }, |
| 63 { |
| 64 Id: "faz", |
| 65 Project: "baz", |
| 66 Schedule: "with 1m interval", |
| 67 State: &scheduler.JobState{Kind: "SUS
PENDED"}, |
| 68 }, |
| 69 }) |
| 70 }) |
| 71 |
| 72 Convey("One Project", func() { |
| 73 fakeEng.getProjectJobs = func(projectID string) ([]*engi
ne.Job, error) { |
| 74 So(projectID, ShouldEqual, "bar") |
| 75 return []*engine.Job{ |
| 76 { |
| 77 JobID: "foo", |
| 78 ProjectID: "bar", |
| 79 Schedule: "0 * * * * * *", |
| 80 State: engine.JobState{State
: engine.JobStateRunning}, |
| 81 }, |
| 82 }, nil |
| 83 } |
| 84 reply, err := ss.GetJobs(ctx, &scheduler.JobsRequest{Pro
ject: "bar"}) |
| 85 So(err, ShouldBeNil) |
| 86 So(reply.GetJobs(), ShouldResemble, []*scheduler.JobWith
State{ |
| 87 { |
| 88 Id: "foo", |
| 89 Project: "bar", |
| 90 Schedule: "0 * * * * * *", |
| 91 State: &scheduler.JobState{Kind: "RUN
NING"}, |
| 92 }, |
| 93 }) |
| 94 }) |
| 95 }) |
| 96 } |
| 97 |
| 98 //// |
| 99 |
| 100 func newTestEngine() (*fakeEngine, catalog.Catalog) { |
| 101 cat := catalog.New("scheduler.cfg") |
| 102 return &fakeEngine{}, cat |
| 103 } |
| 104 |
| 105 type fakeEngine struct { |
| 106 getAllJobs func() ([]*engine.Job, error) |
| 107 getProjectJobs func(projectID string) ([]*engine.Job, error) |
| 108 } |
| 109 |
| 110 func (f *fakeEngine) GetAllProjects(c context.Context) ([]string, error) { |
| 111 panic("not implemented") |
| 112 } |
| 113 |
| 114 func (f *fakeEngine) GetAllJobs(c context.Context) ([]*engine.Job, error) { |
| 115 return f.getAllJobs() |
| 116 } |
| 117 |
| 118 func (f *fakeEngine) GetProjectJobs(c context.Context, projectID string) ([]*eng
ine.Job, error) { |
| 119 return f.getProjectJobs(projectID) |
| 120 } |
| 121 |
| 122 func (f *fakeEngine) GetJob(c context.Context, jobID string) (*engine.Job, error
) { |
| 123 panic("not implemented") |
| 124 } |
| 125 |
| 126 func (f *fakeEngine) ListInvocations(c context.Context, jobID string, pageSize i
nt, cursor string) ([]*engine.Invocation, string, error) { |
| 127 panic("not implemented") |
| 128 } |
| 129 |
| 130 func (f *fakeEngine) GetInvocation(c context.Context, jobID string, invID int64)
(*engine.Invocation, error) { |
| 131 panic("not implemented") |
| 132 } |
| 133 |
| 134 func (f *fakeEngine) GetInvocationsByNonce(c context.Context, invNonce int64) ([
]*engine.Invocation, error) { |
| 135 panic("not implemented") |
| 136 } |
| 137 |
| 138 func (f *fakeEngine) UpdateProjectJobs(c context.Context, projectID string, defs
[]catalog.Definition) error { |
| 139 panic("not implemented") |
| 140 } |
| 141 |
| 142 func (f *fakeEngine) ResetAllJobsOnDevServer(c context.Context) error { |
| 143 panic("not implemented") |
| 144 } |
| 145 |
| 146 func (f *fakeEngine) ExecuteSerializedAction(c context.Context, body []byte, ret
ryCount int) error { |
| 147 panic("not implemented") |
| 148 } |
| 149 |
| 150 func (f *fakeEngine) ProcessPubSubPush(c context.Context, body []byte) error { |
| 151 panic("not implemented") |
| 152 } |
| 153 |
| 154 func (f *fakeEngine) PullPubSubOnDevServer(c context.Context, taskManagerName st
ring, publisher string) error { |
| 155 panic("not implemented") |
| 156 } |
| 157 |
| 158 func (f *fakeEngine) TriggerInvocation(c context.Context, jobID string, triggere
dBy identity.Identity) (int64, error) { |
| 159 panic("not implemented") |
| 160 } |
| 161 |
| 162 func (f *fakeEngine) PauseJob(c context.Context, jobID string, who identity.Iden
tity) error { |
| 163 panic("not implemented") |
| 164 } |
| 165 |
| 166 func (f *fakeEngine) ResumeJob(c context.Context, jobID string, who identity.Ide
ntity) error { |
| 167 panic("not implemented") |
| 168 } |
| 169 |
| 170 func (f *fakeEngine) AbortInvocation(c context.Context, jobID string, invID int6
4, who identity.Identity) error { |
| 171 panic("not implemented") |
| 172 } |
| 173 |
| 174 func (f *fakeEngine) AbortJob(c context.Context, jobID string, who identity.Iden
tity) error { |
| 175 panic("not implemented") |
| 176 } |
| OLD | NEW |