| 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 dm | 5 package dm |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 . "github.com/luci/luci-go/common/testing/assertions" | 10 . "github.com/luci/luci-go/common/testing/assertions" |
| 11 . "github.com/smartystreets/goconvey/convey" | 11 . "github.com/smartystreets/goconvey/convey" |
| 12 ) | 12 ) |
| 13 | 13 |
| 14 func TestAttemptState(t *testing.T) { | 14 func TestAttemptState(t *testing.T) { |
| 15 t.Parallel() | 15 t.Parallel() |
| 16 | 16 |
| 17 Convey("Evolve", t, func() { | 17 Convey("Evolve", t, func() { |
| 18 Convey("Identity", func() { | 18 Convey("Identity", func() { |
| 19 » » » s := Attempt_NEEDS_EXECUTION | 19 » » » s := Attempt_SCHEDULING |
| 20 » » » So(s.Evolve(Attempt_NEEDS_EXECUTION), ShouldBeNil) | 20 » » » So(s.Evolve(Attempt_SCHEDULING), ShouldBeNil) |
| 21 » » » So(s, ShouldEqual, Attempt_NEEDS_EXECUTION) | 21 » » » So(s, ShouldEqual, Attempt_SCHEDULING) |
| 22 }) | 22 }) |
| 23 | 23 |
| 24 Convey("Transition", func() { | 24 Convey("Transition", func() { |
| 25 s := Attempt_EXECUTING | 25 s := Attempt_EXECUTING |
| 26 » » » So(s.Evolve(Attempt_ADDING_DEPS), ShouldBeNil) | 26 » » » So(s.Evolve(Attempt_WAITING), ShouldBeNil) |
| 27 » » » So(s, ShouldEqual, Attempt_ADDING_DEPS) | 27 » » » So(s, ShouldEqual, Attempt_WAITING) |
| 28 }) | 28 }) |
| 29 | 29 |
| 30 Convey("Invalid starting transistion", func() { | 30 Convey("Invalid starting transistion", func() { |
| 31 » » » s := Attempt_NEEDS_EXECUTION | 31 » » » s := Attempt_SCHEDULING |
| 32 » » » So(s.Evolve(Attempt_FINISHED), ShouldErrLike, "invalid s
tate transition NEEDS_EXECUTION -> FINISHED") | 32 » » » So(s.Evolve(Attempt_FINISHED), ShouldErrLike, "invalid s
tate transition SCHEDULING -> FINISHED") |
| 33 » » » So(s, ShouldEqual, Attempt_NEEDS_EXECUTION) | 33 » » » So(s, ShouldEqual, Attempt_SCHEDULING) |
| 34 }) | 34 }) |
| 35 | 35 |
| 36 Convey("Invalid ending transistion", func() { | 36 Convey("Invalid ending transistion", func() { |
| 37 » » » s := Attempt_BLOCKED | 37 » » » s := Attempt_WAITING |
| 38 » » » So(s.Evolve(Attempt_FINISHED), ShouldErrLike, "invalid s
tate transition BLOCKED -> FINISHED") | 38 » » » So(s.Evolve(Attempt_FINISHED), ShouldErrLike, "invalid s
tate transition WAITING -> FINISHED") |
| 39 » » » So(s, ShouldEqual, Attempt_BLOCKED) | 39 » » » So(s, ShouldEqual, Attempt_WAITING) |
| 40 }) | 40 }) |
| 41 | 41 |
| 42 Convey("MustEvolve", func() { | 42 Convey("MustEvolve", func() { |
| 43 s := Attempt_FINISHED | 43 s := Attempt_FINISHED |
| 44 » » » So(func() { s.MustEvolve(Attempt_NEEDS_EXECUTION) }, Sho
uldPanic) | 44 » » » So(func() { s.MustEvolve(Attempt_SCHEDULING) }, ShouldPa
nic) |
| 45 }) | 45 }) |
| 46 }) | 46 }) |
| 47 } | 47 } |
| OLD | NEW |