| 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/service/datastore" | 10 "github.com/luci/gae/service/datastore" |
| 11 "github.com/luci/luci-go/appengine/cmd/dm/model" | 11 "github.com/luci/luci-go/appengine/cmd/dm/model" |
| 12 "github.com/luci/luci-go/appengine/tumble" | |
| 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/testing/assertions" | 13 . "github.com/luci/luci-go/common/testing/assertions" |
| 15 . "github.com/smartystreets/goconvey/convey" | 14 . "github.com/smartystreets/goconvey/convey" |
| 16 ) | 15 ) |
| 17 | 16 |
| 18 func TestEnsureAttempt(t *testing.T) { | 17 func TestEnsureAttempt(t *testing.T) { |
| 19 t.Parallel() | 18 t.Parallel() |
| 20 | 19 |
| 21 Convey("EnsureGraphData (Ensuring attempts)", t, func() { | 20 Convey("EnsureGraphData (Ensuring attempts)", t, func() { |
| 22 » » ttest := &tumble.Testing{} | 21 » » ttest, c, _, s := testSetup() |
| 23 » » c := ttest.Context() | |
| 24 ds := datastore.Get(c) | 22 ds := datastore.Get(c) |
| 25 s := newDecoratedDeps() | |
| 26 | 23 |
| 27 Convey("bad", func() { | 24 Convey("bad", func() { |
| 28 Convey("no quest", func() { | 25 Convey("no quest", func() { |
| 29 _, err := s.EnsureGraphData(c, &dm.EnsureGraphDa
taReq{ | 26 _, err := s.EnsureGraphData(c, &dm.EnsureGraphDa
taReq{ |
| 30 Attempts: dm.NewAttemptList(map[string][
]uint32{"quest": {1}}), | 27 Attempts: dm.NewAttemptList(map[string][
]uint32{"quest": {1}}), |
| 31 }) | 28 }) |
| 32 So(err, ShouldBeRPCInvalidArgument, | 29 So(err, ShouldBeRPCInvalidArgument, |
| 33 `cannot create attempts for absent quest
"quest"`) | 30 `cannot create attempts for absent quest
"quest"`) |
| 34 }) | 31 }) |
| 35 Convey("mismatched quest", func() { | 32 Convey("mismatched quest", func() { |
| 36 _, err := s.EnsureGraphData(c, &dm.EnsureGraphDa
taReq{ | 33 _, err := s.EnsureGraphData(c, &dm.EnsureGraphDa
taReq{ |
| 37 » » » » » Quest: []*dm.Quest_Desc{dm.NewQuestDe
sc("foof", "{}")}, | 34 » » » » » Quest: []*dm.Quest_Desc{dm.NewQuestDe
sc("fakeDistributor", "{}", nil)}, |
| 38 Attempts: dm.NewAttemptList(map[string][
]uint32{"quest": {1}}), | 35 Attempts: dm.NewAttemptList(map[string][
]uint32{"quest": {1}}), |
| 39 }) | 36 }) |
| 40 So(err, ShouldErrLike, "must have a matching Att
empts entry") | 37 So(err, ShouldErrLike, "must have a matching Att
empts entry") |
| 41 }) | 38 }) |
| 42 }) | 39 }) |
| 43 | 40 |
| 44 Convey("good", func() { | 41 Convey("good", func() { |
| 45 » » » desc := dm.NewQuestDesc("swarming", `{"hi": "there"}`) | 42 » » » desc := dm.NewQuestDesc("fakeDistributor", `{"hi": "ther
e"}`, nil) |
| 46 » » » q, err := model.NewQuest(c, desc) | 43 » » » So(desc.Normalize(), ShouldBeNil) |
| 47 » » » So(err, ShouldBeNil) | 44 » » » q := model.NewQuest(c, desc) |
| 48 rsp, err := s.EnsureGraphData(c, &dm.EnsureGraphDataReq{ | 45 rsp, err := s.EnsureGraphData(c, &dm.EnsureGraphDataReq{ |
| 49 Quest: []*dm.Quest_Desc{desc}, | 46 Quest: []*dm.Quest_Desc{desc}, |
| 50 Attempts: dm.NewAttemptList(map[string][]uint32{
q.ID: {1}}), | 47 Attempts: dm.NewAttemptList(map[string][]uint32{
q.ID: {1}}), |
| 51 }) | 48 }) |
| 52 So(err, ShouldBeNil) | 49 So(err, ShouldBeNil) |
| 53 So(rsp.Accepted, ShouldBeTrue) | 50 So(rsp.Accepted, ShouldBeTrue) |
| 54 ttest.Drain(c) | 51 ttest.Drain(c) |
| 55 So(ds.Get(&model.Attempt{ID: *dm.NewAttemptID(q.ID, 1)})
, ShouldBeNil) | 52 So(ds.Get(&model.Attempt{ID: *dm.NewAttemptID(q.ID, 1)})
, ShouldBeNil) |
| 56 }) | 53 }) |
| 57 | 54 |
| 58 }) | 55 }) |
| 59 } | 56 } |
| OLD | NEW |