Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(623)

Unified Diff: mstate/life_test.go

Issue 6527047: mstate: add tests for ops w.r.t. life cycle
Patch Set: mstate: add tests for ops w.r.t. life cycle Created 12 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mstate/life.go ('k') | mstate/machine.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mstate/life_test.go
=== modified file 'mstate/life_test.go'
--- mstate/life_test.go 2012-08-29 10:05:26 +0000
+++ mstate/life_test.go 2012-09-18 18:41:49 +0000
@@ -200,3 +200,40 @@
}
}
}
+
+const (
+ notAliveErr = ".*: not found or not alive"
+ noErr = ""
+)
+
+type lifer interface {
+ Die() error
+ Kill() error
+ Life() state.Life
+}
+
+func runLifeChecks(c *C, obj lifer, expectErr string, checks []func() error) {
+ for i, check := range checks {
+ c.Logf("check %d when %v", i, obj.Life())
+ err := check()
+ if expectErr == noErr {
+ c.Assert(err, IsNil)
+ } else {
+ c.Assert(err, ErrorMatches, expectErr)
+ }
+ }
+}
+
+// testWhenDying sets obj to Dying and Dead in turn, and asserts
+// that the errors from the given checks match aliveErr, dyingErr and deadErr
+// in each respective life state.
+func testWhenDying(c *C, obj lifer, dyingErr, deadErr string, checks ...func() error) {
+ c.Logf("checking life of %v (%T)", obj, obj)
+ runLifeChecks(c, obj, noErr, checks)
+ err := obj.Kill()
+ c.Assert(err, IsNil)
+ runLifeChecks(c, obj, dyingErr, checks)
+ err = obj.Die()
+ c.Assert(err, IsNil)
+ runLifeChecks(c, obj, deadErr, checks)
+}
« no previous file with comments | « mstate/life.go ('k') | mstate/machine.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b