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 mutate | 5 package mutate |
6 | 6 |
7 import ( | 7 import ( |
8 "testing" | 8 "testing" |
9 "time" | 9 "time" |
10 | 10 |
11 "github.com/luci/gae/impl/memory" | 11 "github.com/luci/gae/impl/memory" |
12 "github.com/luci/gae/service/datastore" | 12 "github.com/luci/gae/service/datastore" |
13 "github.com/luci/luci-go/appengine/cmd/dm/model" | 13 "github.com/luci/luci-go/appengine/cmd/dm/model" |
14 » "github.com/luci/luci-go/appengine/tumble" | 14 » //"github.com/luci/luci-go/appengine/tumble" |
15 "github.com/luci/luci-go/common/api/dm/service/v1" | 15 "github.com/luci/luci-go/common/api/dm/service/v1" |
16 "github.com/luci/luci-go/common/clock/testclock" | 16 "github.com/luci/luci-go/common/clock/testclock" |
17 . "github.com/luci/luci-go/common/testing/assertions" | 17 . "github.com/luci/luci-go/common/testing/assertions" |
18 . "github.com/smartystreets/goconvey/convey" | 18 . "github.com/smartystreets/goconvey/convey" |
19 "golang.org/x/net/context" | 19 "golang.org/x/net/context" |
20 ) | 20 ) |
21 | 21 |
22 func TestFinishAttempt(t *testing.T) { | 22 func TestFinishAttempt(t *testing.T) { |
23 t.Parallel() | 23 t.Parallel() |
24 | 24 |
(...skipping 23 matching lines...) Expand all Loading... |
48 ak := ds.KeyForObj(a) | 48 ak := ds.KeyForObj(a) |
49 ar := &model.AttemptResult{Attempt: ak} | 49 ar := &model.AttemptResult{Attempt: ak} |
50 e := &model.Execution{ | 50 e := &model.Execution{ |
51 ID: 1, Attempt: ak, State: dm.Execution_RUNNING,
Token: []byte("exekey")} | 51 ID: 1, Attempt: ak, State: dm.Execution_RUNNING,
Token: []byte("exekey")} |
52 | 52 |
53 So(ds.Put(a, e), ShouldBeNil) | 53 So(ds.Put(a, e), ShouldBeNil) |
54 | 54 |
55 Convey("Good", func() { | 55 Convey("Good", func() { |
56 muts, err := fa.RollForward(c) | 56 muts, err := fa.RollForward(c) |
57 So(err, ShouldBeNil) | 57 So(err, ShouldBeNil) |
58 » » » » So(muts, ShouldResemble, []tumble.Mutation{ | 58 » » » » So(muts, ShouldBeEmpty) |
59 » » » » » &RecordCompletion{For: &a.ID}}) | |
60 | 59 |
61 So(ds.Get(a, e, ar), ShouldBeNil) | 60 So(ds.Get(a, e, ar), ShouldBeNil) |
62 So(e.Token, ShouldBeEmpty) | 61 So(e.Token, ShouldBeEmpty) |
63 So(a.State, ShouldEqual, dm.Attempt_FINISHED) | |
64 So(a.ResultExpiration, ShouldResemble, | 62 So(a.ResultExpiration, ShouldResemble, |
65 testclock.TestTimeUTC.Round(time.Microse
cond)) | 63 testclock.TestTimeUTC.Round(time.Microse
cond)) |
66 So(ar.Data, ShouldResemble, `{"result": true}`) | 64 So(ar.Data, ShouldResemble, `{"result": true}`) |
67 }) | 65 }) |
68 | 66 |
69 Convey("Bad ExecutionKey", func() { | 67 Convey("Bad ExecutionKey", func() { |
70 fa.Auth.Token = []byte("wat") | 68 fa.Auth.Token = []byte("wat") |
71 _, err := fa.RollForward(c) | 69 _, err := fa.RollForward(c) |
72 » » » » So(err, ShouldBeRPCUnauthenticated, "execution A
uth") | 70 » » » » So(err, ShouldBeRPCPermissionDenied, "execution
Auth") |
73 | 71 |
74 So(ds.Get(a, e), ShouldBeNil) | 72 So(ds.Get(a, e), ShouldBeNil) |
75 So(e.Token, ShouldNotBeEmpty) | 73 So(e.Token, ShouldNotBeEmpty) |
76 So(a.State, ShouldEqual, dm.Attempt_EXECUTING) | 74 So(a.State, ShouldEqual, dm.Attempt_EXECUTING) |
77 | 75 |
78 So(ds.Get(ar), ShouldEqual, datastore.ErrNoSuchE
ntity) | 76 So(ds.Get(ar), ShouldEqual, datastore.ErrNoSuchE
ntity) |
79 }) | 77 }) |
80 | 78 |
81 }) | 79 }) |
82 }) | 80 }) |
83 } | 81 } |
OLD | NEW |