| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package deps | 5 package deps |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "github.com/luci/gae/impl/memory" | |
| 11 "github.com/luci/gae/service/datastore" | 10 "github.com/luci/gae/service/datastore" |
| 12 "github.com/luci/luci-go/appengine/cmd/dm/model" | 11 "github.com/luci/luci-go/appengine/cmd/dm/model" |
| 13 "github.com/luci/luci-go/common/api/dm/service/v1" | 12 "github.com/luci/luci-go/common/api/dm/service/v1" |
| 14 "github.com/luci/luci-go/common/clock/testclock" | 13 "github.com/luci/luci-go/common/clock/testclock" |
| 15 google_pb "github.com/luci/luci-go/common/proto/google" | 14 google_pb "github.com/luci/luci-go/common/proto/google" |
| 16 . "github.com/luci/luci-go/common/testing/assertions" | 15 . "github.com/luci/luci-go/common/testing/assertions" |
| 17 . "github.com/smartystreets/goconvey/convey" | 16 . "github.com/smartystreets/goconvey/convey" |
| 18 "golang.org/x/net/context" | |
| 19 ) | 17 ) |
| 20 | 18 |
| 21 func TestFinishAttempt(t *testing.T) { | 19 func TestFinishAttempt(t *testing.T) { |
| 22 t.Parallel() | 20 t.Parallel() |
| 23 | 21 |
| 24 Convey("FinishAttempt", t, func() { | 22 Convey("FinishAttempt", t, func() { |
| 25 » » c := memory.Use(context.Background()) | 23 » » _, c, _, s := testSetup() |
| 26 ds := datastore.Get(c) | 24 ds := datastore.Get(c) |
| 27 s := newDecoratedDeps() | |
| 28 | 25 |
| 29 So(ds.Put(&model.Quest{ID: "quest"}), ShouldBeNil) | 26 So(ds.Put(&model.Quest{ID: "quest"}), ShouldBeNil) |
| 30 a := &model.Attempt{ | 27 a := &model.Attempt{ |
| 31 ID: *dm.NewAttemptID("quest", 1), | 28 ID: *dm.NewAttemptID("quest", 1), |
| 32 State: dm.Attempt_EXECUTING, | 29 State: dm.Attempt_EXECUTING, |
| 33 CurExecution: 1, | 30 CurExecution: 1, |
| 34 } | 31 } |
| 32 e := model.ExecutionFromID(c, dm.NewExecutionID("quest", 1, 1)) |
| 33 ar := &model.AttemptResult{Attempt: ds.KeyForObj(a)} |
| 35 So(ds.Put(a), ShouldBeNil) | 34 So(ds.Put(a), ShouldBeNil) |
| 36 So(ds.Put(&model.Execution{ | 35 So(ds.Put(&model.Execution{ |
| 37 ID: 1, Attempt: ds.KeyForObj(a), Token: []byte("exKey"), | 36 ID: 1, Attempt: ds.KeyForObj(a), Token: []byte("exKey"), |
| 38 State: dm.Execution_RUNNING}), ShouldBeNil) | 37 State: dm.Execution_RUNNING}), ShouldBeNil) |
| 39 | 38 |
| 40 req := &dm.FinishAttemptReq{ | 39 req := &dm.FinishAttemptReq{ |
| 41 Auth: &dm.Execution_Auth{ | 40 Auth: &dm.Execution_Auth{ |
| 42 Id: dm.NewExecutionID(a.ID.Quest, a.ID.Id, 1)
, | 41 Id: dm.NewExecutionID(a.ID.Quest, a.ID.Id, 1)
, |
| 43 Token: []byte("exKey"), | 42 Token: []byte("exKey"), |
| 44 }, | 43 }, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 57 req.JsonResult = `i am not valid json` | 56 req.JsonResult = `i am not valid json` |
| 58 _, err := s.FinishAttempt(c, req) | 57 _, err := s.FinishAttempt(c, req) |
| 59 So(err, ShouldErrLike, "invalid character 'i'") | 58 So(err, ShouldErrLike, "invalid character 'i'") |
| 60 }) | 59 }) |
| 61 }) | 60 }) |
| 62 | 61 |
| 63 Convey("good", func() { | 62 Convey("good", func() { |
| 64 _, err := s.FinishAttempt(c, req) | 63 _, err := s.FinishAttempt(c, req) |
| 65 So(err, ShouldBeNil) | 64 So(err, ShouldBeNil) |
| 66 | 65 |
| 67 » » » So(ds.Get(a), ShouldBeNil) | 66 » » » So(ds.GetMulti([]interface{}{a, ar, e}), ShouldBeNil) |
| 68 » » » So(a.State, ShouldEqual, dm.Attempt_FINISHED) | 67 » » » So(a.State, ShouldEqual, dm.Attempt_EXECUTING) |
| 68 » » » So(e.State, ShouldEqual, dm.Execution_STOPPING) |
| 69 |
| 70 » » » So(a.ResultSize, ShouldEqual, 21) |
| 71 » » » So(ar.Size, ShouldEqual, 21) |
| 69 }) | 72 }) |
| 70 | 73 |
| 71 }) | 74 }) |
| 72 } | 75 } |
| OLD | NEW |