Index: worker/uniter/uniter_test.go |
=== modified file 'worker/uniter/uniter_test.go' |
--- worker/uniter/uniter_test.go 2012-10-19 14:39:52 +0000 |
+++ worker/uniter/uniter_test.go 2012-10-25 11:06:05 +0000 |
@@ -136,13 +136,36 @@ |
c.Assert(err, IsNil) |
} |
-func (ctx *context) matchLogHooks(c *C) (bool, bool) { |
- hookPattern := fmt.Sprintf(`^.* JUJU u/0(| [a-z-]+:[0-9]+): UniterSuite-%d ([0-9a-z-/ ]+)$`, ctx.id) |
+func (ctx *context) matchLogHooks(c *C) (match bool, overshoot bool) { |
+ // hookPattern matches juju-log calls as generated by writeHook. |
+ hookPattern := fmt.Sprintf(`^.* JUJU `+ |
+ `u/0(| [a-z-]+:[0-9]+)`+ // juju-log badge; group matches relation id |
+ `: UniterSuite-%d`+ // test badge; prevents cross-pollution |
+ ` ([0-9a-z-/ ]+)$`, // foo-relation-joined bar/123 |
+ ctx.id, |
+ ) |
+ // donePattern matches uniter logging that indicates a hook has run. |
+ donePattern := `^.* JUJU (ran "[a-z-]+" hook|hook failed)` |
hookRegexp := regexp.MustCompile(hookPattern) |
+ doneRegexp := regexp.MustCompile(donePattern) |
+ |
+ // pending is empty while we scan for a new hook, and holds a value while |
+ // we scan for output indicating that hook execution has finished; at which |
+ // point, we add it to... |
+ pending := "" |
+ // ...actual, which holds a list of executed hooks, with basic information |
+ // about the relation context, and which will be compared against ctx's |
+ // complete list of expected hooks. |
var actual []string |
for _, line := range strings.Split(c.GetTestLog(), "\n") { |
- if parts := hookRegexp.FindStringSubmatch(line); parts != nil { |
- actual = append(actual, parts[2]+parts[1]) |
+ if pending == "" { |
+ if parts := hookRegexp.FindStringSubmatch(line); parts != nil { |
+ // "hook-name[ JUJU_REMOTE_UNIT]" + "[ JUJU_RELATION_ID] |
+ pending = parts[2] + parts[1] |
+ } |
+ } else if doneRegexp.MatchString(line) { |
+ actual = append(actual, pending) |
+ pending = "" |
} |
} |
c.Logf("actual: %#v", actual) |