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

Unified Diff: worker/uniter/uniter_test.go

Issue 6736058: uniter: hook tests more careful
Patch Set: uniter: hook tests more careful Created 12 years, 5 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 | « [revision details] ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « [revision details] ('k') | no next file » | no next file with comments »

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