| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. | 1 // Copyright 2015 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 e, _ := newTestEngine() | 80 e, _ := newTestEngine() |
| 81 | 81 |
| 82 // Doing nothing. | 82 // Doing nothing. |
| 83 So(e.UpdateProjectJobs(c, "abc", []catalog.Definition{}), Should
BeNil) | 83 So(e.UpdateProjectJobs(c, "abc", []catalog.Definition{}), Should
BeNil) |
| 84 So(allJobs(c), ShouldResemble, []Job{}) | 84 So(allJobs(c), ShouldResemble, []Job{}) |
| 85 | 85 |
| 86 // Adding a new job (ticks every 5 sec). | 86 // Adding a new job (ticks every 5 sec). |
| 87 So(e.UpdateProjectJobs(c, "abc", []catalog.Definition{ | 87 So(e.UpdateProjectJobs(c, "abc", []catalog.Definition{ |
| 88 { | 88 { |
| 89 JobID: "abc/1", | 89 JobID: "abc/1", |
| 90 Revision: "rev1", | |
| 91 Schedule: "*/5 * * * * * *", | |
| 92 }}), ShouldBeNil) | |
| 93 So(allJobs(c), ShouldResemble, []Job{ | |
| 94 { | |
| 95 JobID: "abc/1", | |
| 96 ProjectID: "abc", | |
| 97 Revision: "rev1", | |
| 98 Enabled: true, | |
| 99 Schedule: "*/5 * * * * * *", | |
| 100 State: JobState{ | |
| 101 State: "SCHEDULED", | |
| 102 TickNonce: 6278013164014963328, | |
| 103 TickTime: epoch.Add(5 * time.Second), | |
| 104 }, | |
| 105 }, | |
| 106 }) | |
| 107 | |
| 108 // TODO(tandrii): delete and update above definition after no-AC
L -> ACL transition. | |
| 109 // Simulate ACL version roll without change of project config. | |
| 110 So(e.UpdateProjectJobs(c, "abc", []catalog.Definition{ | |
| 111 { | |
| 112 JobID: "abc/1", | |
| 113 Revision: "rev1", | 90 Revision: "rev1", |
| 114 Schedule: "*/5 * * * * * *", | 91 Schedule: "*/5 * * * * * *", |
| 115 Acls: acl.GrantsByRole{Readers: []string{"gr
oup:r"}, Owners: []string{"groups:o"}}, | 92 Acls: acl.GrantsByRole{Readers: []string{"gr
oup:r"}, Owners: []string{"groups:o"}}, |
| 116 }}), ShouldBeNil) | 93 }}), ShouldBeNil) |
| 117 So(allJobs(c), ShouldResemble, []Job{ | 94 So(allJobs(c), ShouldResemble, []Job{ |
| 118 { | 95 { |
| 119 JobID: "abc/1", | 96 JobID: "abc/1", |
| 120 ProjectID: "abc", | 97 ProjectID: "abc", |
| 121 Revision: "rev1", | 98 Revision: "rev1", |
| 122 Enabled: true, | 99 Enabled: true, |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 So(err, ShouldBeNil) | 542 So(err, ShouldBeNil) |
| 566 | 543 |
| 567 So(newer, ShouldBeLessThan, older) | 544 So(newer, ShouldBeLessThan, older) |
| 568 }) | 545 }) |
| 569 } | 546 } |
| 570 | 547 |
| 571 func TestQueries(t *testing.T) { | 548 func TestQueries(t *testing.T) { |
| 572 Convey("with mock data", t, func() { | 549 Convey("with mock data", t, func() { |
| 573 c := newTestContext(epoch) | 550 c := newTestContext(epoch) |
| 574 e, _ := newTestEngine() | 551 e, _ := newTestEngine() |
| 575 » » // TODO(tandrii): remove aclDefault once all Jobs have ACLs. | 552 » » aclPublic := acl.GrantsByRole{Readers: []string{"group:all"}, Ow
ners: []string{"group:administrators"}} |
| 576 » » aclDefault := acl.GrantsByRole{} | |
| 577 aclSome := acl.GrantsByRole{Readers: []string{"group:some"}} | 553 aclSome := acl.GrantsByRole{Readers: []string{"group:some"}} |
| 578 aclOne := acl.GrantsByRole{Owners: []string{"one@example.com"}} | 554 aclOne := acl.GrantsByRole{Owners: []string{"one@example.com"}} |
| 579 aclAdmin := acl.GrantsByRole{Readers: []string{"group:administra
tors"}, Owners: []string{"group:administrators"}} | 555 aclAdmin := acl.GrantsByRole{Readers: []string{"group:administra
tors"}, Owners: []string{"group:administrators"}} |
| 580 | 556 |
| 581 ctxAnon := auth.WithState(c, &authtest.FakeState{ | 557 ctxAnon := auth.WithState(c, &authtest.FakeState{ |
| 582 » » » Identity: "anonymous:anonymous", | 558 » » » Identity: "anonymous:anonymous", |
| 559 » » » IdentityGroups: []string{"all"}, |
| 583 }) | 560 }) |
| 584 ctxOne := auth.WithState(c, &authtest.FakeState{ | 561 ctxOne := auth.WithState(c, &authtest.FakeState{ |
| 585 Identity: "user:one@example.com", | 562 Identity: "user:one@example.com", |
| 586 IdentityGroups: []string{"all"}, | 563 IdentityGroups: []string{"all"}, |
| 587 }) | 564 }) |
| 588 ctxSome := auth.WithState(c, &authtest.FakeState{ | 565 ctxSome := auth.WithState(c, &authtest.FakeState{ |
| 589 Identity: "user:some@example.com", | 566 Identity: "user:some@example.com", |
| 590 » » » IdentityGroups: []string{"some"}, | 567 » » » IdentityGroups: []string{"all", "some"}, |
| 591 }) | 568 }) |
| 592 ctxAdmin := auth.WithState(c, &authtest.FakeState{ | 569 ctxAdmin := auth.WithState(c, &authtest.FakeState{ |
| 593 Identity: "user:admin@example.com", | 570 Identity: "user:admin@example.com", |
| 594 » » » IdentityGroups: []string{"administrators"}, | 571 » » » IdentityGroups: []string{"administrators", "all"}, |
| 595 }) | 572 }) |
| 596 | 573 |
| 597 So(ds.Put(c, | 574 So(ds.Put(c, |
| 598 &Job{JobID: "abc/1", ProjectID: "abc", Enabled: true, Ac
ls: aclOne}, | 575 &Job{JobID: "abc/1", ProjectID: "abc", Enabled: true, Ac
ls: aclOne}, |
| 599 &Job{JobID: "abc/2", ProjectID: "abc", Enabled: true, Ac
ls: aclSome}, | 576 &Job{JobID: "abc/2", ProjectID: "abc", Enabled: true, Ac
ls: aclSome}, |
| 600 » » » &Job{JobID: "abc/3", ProjectID: "abc", Enabled: true, Ac
ls: aclDefault}, | 577 » » » &Job{JobID: "abc/3", ProjectID: "abc", Enabled: true, Ac
ls: aclPublic}, |
| 601 » » » &Job{JobID: "def/1", ProjectID: "def", Enabled: true, Ac
ls: aclDefault}, | 578 » » » &Job{JobID: "def/1", ProjectID: "def", Enabled: true, Ac
ls: aclPublic}, |
| 602 » » » &Job{JobID: "def/2", ProjectID: "def", Enabled: false, A
cls: aclDefault}, | 579 » » » &Job{JobID: "def/2", ProjectID: "def", Enabled: false, A
cls: aclPublic}, |
| 603 &Job{JobID: "secret/1", ProjectID: "secret", Enabled: tr
ue, Acls: aclAdmin}, | 580 &Job{JobID: "secret/1", ProjectID: "secret", Enabled: tr
ue, Acls: aclAdmin}, |
| 604 ), ShouldBeNil) | 581 ), ShouldBeNil) |
| 605 | 582 |
| 606 job1 := ds.NewKey(c, "Job", "abc/1", 0, nil) | 583 job1 := ds.NewKey(c, "Job", "abc/1", 0, nil) |
| 607 job2 := ds.NewKey(c, "Job", "abc/2", 0, nil) | 584 job2 := ds.NewKey(c, "Job", "abc/2", 0, nil) |
| 608 job3 := ds.NewKey(c, "Job", "abc/3", 0, nil) | 585 job3 := ds.NewKey(c, "Job", "abc/3", 0, nil) |
| 609 So(ds.Put(c, | 586 So(ds.Put(c, |
| 610 &Invocation{ID: 1, JobKey: job1, InvocationNonce: 123}, | 587 &Invocation{ID: 1, JobKey: job1, InvocationNonce: 123}, |
| 611 &Invocation{ID: 2, JobKey: job1, InvocationNonce: 123}, | 588 &Invocation{ID: 2, JobKey: job1, InvocationNonce: 123}, |
| 612 &Invocation{ID: 3, JobKey: job1}, | 589 &Invocation{ID: 3, JobKey: job1}, |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 | 1236 |
| 1260 func ensureOneTask(c context.Context, q string) *tq.Task { | 1237 func ensureOneTask(c context.Context, q string) *tq.Task { |
| 1261 tqt := tq.GetTestable(c) | 1238 tqt := tq.GetTestable(c) |
| 1262 tasks := tqt.GetScheduledTasks()[q] | 1239 tasks := tqt.GetScheduledTasks()[q] |
| 1263 So(len(tasks), ShouldEqual, 1) | 1240 So(len(tasks), ShouldEqual, 1) |
| 1264 for _, t := range tasks { | 1241 for _, t := range tasks { |
| 1265 return t | 1242 return t |
| 1266 } | 1243 } |
| 1267 return nil | 1244 return nil |
| 1268 } | 1245 } |
| OLD | NEW |