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

Unified Diff: scheduler/appengine/apiservers/scheduler_test.go

Issue 2945843002: scheduler WIP: add GetAllJobs api. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: scheduler/appengine/apiservers/scheduler_test.go
diff --git a/scheduler/appengine/apiservers/scheduler_test.go b/scheduler/appengine/apiservers/scheduler_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..8772c6772d73637ee79f53b1847bba10fa569b7d
--- /dev/null
+++ b/scheduler/appengine/apiservers/scheduler_test.go
@@ -0,0 +1,176 @@
+// Copyright 2017 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package apiservers
+
+import (
+ "testing"
+
+ context "golang.org/x/net/context"
+
+ "github.com/luci/luci-go/appengine/gaetesting"
+ "github.com/luci/luci-go/server/auth/identity"
+
+ scheduler "github.com/luci/luci-go/scheduler/api/scheduler/v1"
+ "github.com/luci/luci-go/scheduler/appengine/catalog"
+ "github.com/luci/luci-go/scheduler/appengine/engine"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestGetJobsApi(t *testing.T) {
+ t.Parallel()
+
+ Convey("Scheduler GetJobs API works", t, func() {
+ ctx := gaetesting.TestingContext()
+ fakeEng, catalog := newTestEngine()
+ ss := SchedulerServer{fakeEng, catalog}
+
+ Convey("Empty", func() {
+ fakeEng.getAllJobs = func() ([]*engine.Job, error) { return []*engine.Job{}, nil }
+ reply, err := ss.GetJobs(ctx, nil)
+ So(err, ShouldBeNil)
+ So(len(reply.GetJobs()), ShouldEqual, 0)
+ })
+
+ Convey("All Projects", func() {
+ fakeEng.getAllJobs = func() ([]*engine.Job, error) {
+ return []*engine.Job{
+ {
+ JobID: "foo",
+ ProjectID: "bar",
+ Schedule: "0 * * * * * *",
+ State: engine.JobState{State: engine.JobStateRunning},
+ },
+ {
+ JobID: "faz",
+ ProjectID: "baz",
+ Schedule: "with 1m interval",
+ State: engine.JobState{State: engine.JobStateSuspended},
+ },
+ }, nil
+ }
+ reply, err := ss.GetJobs(ctx, nil)
+ So(err, ShouldBeNil)
+ So(reply.GetJobs(), ShouldResemble, []*scheduler.JobWithState{
+ {
+ Id: "foo",
+ Project: "bar",
+ Schedule: "0 * * * * * *",
+ State: &scheduler.JobState{Kind: "RUNNING"},
+ },
+ {
+ Id: "faz",
+ Project: "baz",
+ Schedule: "with 1m interval",
+ State: &scheduler.JobState{Kind: "SUSPENDED"},
+ },
+ })
+ })
+
+ Convey("One Project", func() {
+ fakeEng.getProjectJobs = func(projectID string) ([]*engine.Job, error) {
+ So(projectID, ShouldEqual, "bar")
+ return []*engine.Job{
+ {
+ JobID: "foo",
+ ProjectID: "bar",
+ Schedule: "0 * * * * * *",
+ State: engine.JobState{State: engine.JobStateRunning},
+ },
+ }, nil
+ }
+ reply, err := ss.GetJobs(ctx, &scheduler.JobsRequest{Project: "bar"})
+ So(err, ShouldBeNil)
+ So(reply.GetJobs(), ShouldResemble, []*scheduler.JobWithState{
+ {
+ Id: "foo",
+ Project: "bar",
+ Schedule: "0 * * * * * *",
+ State: &scheduler.JobState{Kind: "RUNNING"},
+ },
+ })
+ })
+ })
+}
+
+////
+
+func newTestEngine() (*fakeEngine, catalog.Catalog) {
+ cat := catalog.New("scheduler.cfg")
+ return &fakeEngine{}, cat
+}
+
+type fakeEngine struct {
+ getAllJobs func() ([]*engine.Job, error)
+ getProjectJobs func(projectID string) ([]*engine.Job, error)
+}
+
+func (f *fakeEngine) GetAllProjects(c context.Context) ([]string, error) {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) GetAllJobs(c context.Context) ([]*engine.Job, error) {
+ return f.getAllJobs()
+}
+
+func (f *fakeEngine) GetProjectJobs(c context.Context, projectID string) ([]*engine.Job, error) {
+ return f.getProjectJobs(projectID)
+}
+
+func (f *fakeEngine) GetJob(c context.Context, jobID string) (*engine.Job, error) {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) ListInvocations(c context.Context, jobID string, pageSize int, cursor string) ([]*engine.Invocation, string, error) {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) GetInvocation(c context.Context, jobID string, invID int64) (*engine.Invocation, error) {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) GetInvocationsByNonce(c context.Context, invNonce int64) ([]*engine.Invocation, error) {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) UpdateProjectJobs(c context.Context, projectID string, defs []catalog.Definition) error {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) ResetAllJobsOnDevServer(c context.Context) error {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) ExecuteSerializedAction(c context.Context, body []byte, retryCount int) error {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) ProcessPubSubPush(c context.Context, body []byte) error {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) PullPubSubOnDevServer(c context.Context, taskManagerName string, publisher string) error {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) TriggerInvocation(c context.Context, jobID string, triggeredBy identity.Identity) (int64, error) {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) PauseJob(c context.Context, jobID string, who identity.Identity) error {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) ResumeJob(c context.Context, jobID string, who identity.Identity) error {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) AbortInvocation(c context.Context, jobID string, invID int64, who identity.Identity) error {
+ panic("not implemented")
+}
+
+func (f *fakeEngine) AbortJob(c context.Context, jobID string, who identity.Identity) error {
+ panic("not implemented")
+}
« scheduler/appengine/apiservers/scheduler.go ('K') | « scheduler/appengine/apiservers/scheduler.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698