| 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 TestExecutionState(t *testing.T) { | 14 func TestExecutionState(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 := Execution_SCHEDULED | 19 » » » s := Execution_SCHEDULING |
| 20 » » » So(s.Evolve(Execution_SCHEDULED), ShouldBeNil) | 20 » » » So(s.Evolve(Execution_SCHEDULING), ShouldBeNil) |
| 21 » » » So(s, ShouldEqual, Execution_SCHEDULED) | 21 » » » So(s, ShouldEqual, Execution_SCHEDULING) |
| 22 }) | 22 }) |
| 23 | 23 |
| 24 Convey("Transition", func() { | 24 Convey("Transition", func() { |
| 25 s := Execution_RUNNING | 25 s := Execution_RUNNING |
| 26 » » » So(s.Evolve(Execution_FINISHED), ShouldBeNil) | 26 » » » So(s.Evolve(Execution_STOPPING), ShouldBeNil) |
| 27 » » » So(s, ShouldEqual, Execution_FINISHED) | 27 » » » So(s, ShouldEqual, Execution_STOPPING) |
| 28 }) | 28 }) |
| 29 | 29 |
| 30 Convey("Invalid starting transistion", func() { | 30 Convey("Invalid starting transistion", func() { |
| 31 s := Execution_FINISHED | 31 s := Execution_FINISHED |
| 32 » » » So(s.Evolve(Execution_SCHEDULED), ShouldErrLike, "invali
d state transition FINISHED -> SCHEDULE") | 32 » » » So(s.Evolve(Execution_SCHEDULING), ShouldErrLike, "inval
id state transition FINISHED -> SCHEDULING") |
| 33 So(s, ShouldEqual, Execution_FINISHED) | 33 So(s, ShouldEqual, Execution_FINISHED) |
| 34 }) | 34 }) |
| 35 | 35 |
| 36 Convey("Invalid ending transistion", func() { | 36 Convey("Invalid ending transistion", func() { |
| 37 s := Execution_RUNNING | 37 s := Execution_RUNNING |
| 38 » » » So(s.Evolve(Execution_SCHEDULED), ShouldErrLike, "invali
d state transition RUNNING -> SCHEDULED") | 38 » » » So(s.Evolve(Execution_SCHEDULING), ShouldErrLike, "inval
id state transition RUNNING -> SCHEDULING") |
| 39 So(s, ShouldEqual, Execution_RUNNING) | 39 So(s, ShouldEqual, Execution_RUNNING) |
| 40 }) | 40 }) |
| 41 | 41 |
| 42 Convey("MustEvolve", func() { | 42 Convey("MustEvolve", func() { |
| 43 s := Execution_FINISHED | 43 s := Execution_FINISHED |
| 44 » » » So(func() { s.MustEvolve(Execution_SCHEDULED) }, ShouldP
anic) | 44 » » » So(func() { s.MustEvolve(Execution_SCHEDULING) }, Should
Panic) |
| 45 }) | 45 }) |
| 46 }) | 46 }) |
| 47 } | 47 } |
| OLD | NEW |