Index: appengine/cmd/dm/deps/activate_execution_test.go |
diff --git a/appengine/cmd/dm/deps/activate_execution_test.go b/appengine/cmd/dm/deps/activate_execution_test.go |
index d17848785bba65eb3ae9b59cae38699e62ea365e..22b68a65dd01cab3fe7d401f52e6bb3ce170d140 100644 |
--- a/appengine/cmd/dm/deps/activate_execution_test.go |
+++ b/appengine/cmd/dm/deps/activate_execution_test.go |
@@ -7,8 +7,7 @@ package deps |
import ( |
"testing" |
- "github.com/luci/gae/service/datastore" |
- "github.com/luci/luci-go/appengine/tumble" |
+ "github.com/luci/luci-go/appengine/cmd/dm/distributor/fake" |
dm "github.com/luci/luci-go/common/api/dm/service/v1" |
. "github.com/luci/luci-go/common/testing/assertions" |
. "github.com/smartystreets/goconvey/convey" |
@@ -18,65 +17,62 @@ func TestActivateExecution(t *testing.T) { |
t.Parallel() |
Convey("Test ActivateExecution", t, func() { |
- ttest := &tumble.Testing{} |
- c := ttest.Context() |
- ds := datastore.Get(c) |
- _ = ds |
- s := newDecoratedDeps() |
+ ttest, c, dist, s := testSetup() |
- qid := ensureQuest(c, "foo", 1) |
+ qid := s.ensureQuest(c, "foo", 1) |
ttest.Drain(c) |
- realAuth := execute(c, dm.NewAttemptID(qid, 1)) |
eid := dm.NewExecutionID(qid, 1, 1) |
- |
- req := &dm.ActivateExecutionReq{ |
- Auth: &dm.Execution_Auth{Id: eid}, |
- ExecutionToken: []byte("newtok"), |
- } |
- |
- Convey("bad", func() { |
- Convey("wrong token", func() { |
- _, err := s.ActivateExecution(c, req) |
- So(err, ShouldBeRPCUnauthenticated, "failed to activate") |
- }) |
- |
- Convey("wrong token (already activated)", func() { |
- req.Auth.Token = realAuth.Token |
- _, err := s.ActivateExecution(c, req) |
- So(err, ShouldBeNil) |
- |
- req.Auth.Token = []byte("bad sekret") |
- req.ExecutionToken = []byte("random other tok") |
- _, err = s.ActivateExecution(c, req) |
- So(err, ShouldBeRPCUnauthenticated, "failed to activate") |
+ dist.RunTask(c, eid, func(tsk *fake.Task) error { |
+ req := &dm.ActivateExecutionReq{ |
+ Auth: &dm.Execution_Auth{Id: eid}, |
+ ExecutionToken: []byte("sufficiently long new 'random' token"), |
+ } |
+ |
+ Convey("bad", func() { |
+ Convey("wrong token", func() { |
+ _, err := s.ActivateExecution(c, req) |
+ So(err, ShouldBeRPCPermissionDenied, "failed to activate") |
+ }) |
+ |
+ Convey("wrong token (already activated)", func() { |
+ req.Auth.Token = tsk.Auth.Token |
+ _, err := s.ActivateExecution(c, req) |
+ So(err, ShouldBeNil) |
+ |
+ req.Auth.Token = []byte("bad sekret") |
+ req.ExecutionToken = []byte("random other super duper long token") |
+ _, err = s.ActivateExecution(c, req) |
+ So(err, ShouldBeRPCPermissionDenied, "failed to activate") |
+ }) |
+ |
+ Convey("concurrent activation", func() { |
+ req.Auth.Token = tsk.Auth.Token |
+ _, err := s.ActivateExecution(c, req) |
+ So(err, ShouldBeNil) |
+ |
+ req.ExecutionToken = append(req.ExecutionToken, []byte(" (but incorrect)")...) |
+ _, err = s.ActivateExecution(c, req) |
+ So(err, ShouldBeRPCPermissionDenied, "failed to activate") |
+ }) |
}) |
- Convey("concurrent activation", func() { |
- req.Auth.Token = realAuth.Token |
- _, err := s.ActivateExecution(c, req) |
- So(err, ShouldBeNil) |
+ Convey("good", func() { |
+ req.Auth.Token = tsk.Auth.Token |
- req.ExecutionToken = []byte("other newtok") |
- _, err = s.ActivateExecution(c, req) |
- So(err, ShouldBeRPCUnauthenticated, "failed to activate") |
- }) |
- }) |
- |
- Convey("good", func() { |
- req.Auth.Token = realAuth.Token |
- |
- Convey("normal activation", func() { |
- _, err := s.ActivateExecution(c, req) |
- So(err, ShouldBeNil) |
- }) |
+ Convey("normal activation", func() { |
+ _, err := s.ActivateExecution(c, req) |
+ So(err, ShouldBeNil) |
+ }) |
- Convey("repeated activation", func() { |
- _, err := s.ActivateExecution(c, req) |
- So(err, ShouldBeNil) |
- _, err = s.ActivateExecution(c, req) |
- So(err, ShouldBeNil) |
+ Convey("repeated activation", func() { |
+ _, err := s.ActivateExecution(c, req) |
+ So(err, ShouldBeNil) |
+ _, err = s.ActivateExecution(c, req) |
+ So(err, ShouldBeNil) |
+ }) |
}) |
+ return nil |
}) |
}) |
} |