Merge lp:~axwalk/juju-core/logmatches-inexact into lp:~go-bot/juju-core/trunk
Proposed by
Andrew Wilkins
Status: | Merged |
---|---|
Approved by: | Andrew Wilkins |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1986 |
Proposed branch: | lp:~axwalk/juju-core/logmatches-inexact |
Merge into: | lp:~go-bot/juju-core/trunk |
Diff against target: |
160 lines (+83/-28) 2 files modified
testing/checkers/log.go (+33/-28) testing/checkers/log_test.go (+50/-0) |
To merge this branch: | bzr merge lp:~axwalk/juju-core/logmatches-inexact |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+191092@code.launchpad.net |
Commit message
testing/checkers: make LogMatches inexact
In the rare case that we want to check log messages,
we want to check a particular message has been logged,
not check the entirety of the log. This allows for
changes (unrelated additions/removals) in logging
without affecting tests.
Description of the change
testing/checkers: make LogMatches inexact
In the rare case that we want to check log messages,
we want to check a particular message has been logged,
not check the entirety of the log. This allows for
changes (unrelated additions/removals) in logging
without affecting tests.
To post a comment you must log in.
Reviewers: mp+191092_ code.launchpad. net,
Message:
Please take a look.
Description:
testing/checkers: make LogMatches inexact
In the rare case that we want to check log messages,
we want to check a particular message has been logged,
not check the entirety of the log. This allows for
changes (unrelated additions/removals) in logging
without affecting tests.
https:/ /code.launchpad .net/~axwalk/ juju-core/ logmatches- inexact/ +merge/ 191092
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/14430064/
Affected files (+55, -30 lines): checkers/ log.go checkers/ log_test. go
A [revision details]
M testing/
M testing/
Index: [revision details] 20131014040553- f18jp0xnxw45qkt 2
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: testing/ checkers/ log.go checkers/ log.go' checkers/ log.go 2013-10-01 16:46:31 +0000 checkers/ log.go 2013-10-15 02:36:40 +0000 TestLogValues or 1].([]SimpleMes sage) MustCompile( expected[ i].Message) (obtained[ i].Message) { 1].([]string) MustCompile( expected[ i]) (obtained[ i].Message) { SimpleMessage, len(param)) MustCompile( expected[ 0].Message) (msg.Message) {
=== modified file 'testing/
--- testing/
+++ testing/
@@ -36,41 +36,38 @@
default:
return false, "Obtained value must be of type []loggo.
SimpleMessage"
}
- switch params[1].(type) {
+
+ var expected []SimpleMessage
+ switch param := params[1].(type) {
case []SimpleMessage:
- expected := params[
- if len(obtained) != len(expected) {
- return false, ""
- }
- for i := 0; i < len(obtained); i++ {
- if obtained[i].Level != expected[i].Level {
- return false, ""
- }
- re := regexp.
- if !re.MatchString
- return false, ""
- }
- }
- return true, ""
+ expected = param
case []string:
- asString := make([]string, len(obtained))
- for i, val := range obtained {
- asString[i] = val.Message
- }
- expected := params[
- if len(obtained) != len(expected) {
- return false, ""
- }
- for i := 0; i < len(obtained); i++ {
- re := regexp.
- if !re.MatchString
- return false, ""
- }
- }
- return true, ""
+ expected = make([]
+ for i, s := range param {
+ expected[i].Message = s
+ }
default:
return false, "Expected value must be of type []string or
[]SimpleMessage"
}
+
+ for len(expected) > 0 && len(obtained) >= len(expected) {
+ var msg SimpleMessage
+ msg, obtained = obtained[0], obtained[1:]
+ if expected[0].Level != loggo.UNSPECIFIED {
+ if msg.Level != expected[0].Level {
+ continue
+ }
+ }
+ re := regexp.
+ if !re.MatchString
+ continue
+ }
+ expected = expected[1:]
+ }
+ if len(obtained) < len(expected) {
+ return false, ""
+ }
+ return true, ""
}
// LogMatches checks whether a given TestLogValues actually contains the
log
@@ -78,6 +75,10 @@
// compare that the strings in the messages are correct. You can
alternatively
// pass a slice of SimpleMessage and we will check that the log levels are
// also correct.
+//
+// The log may conta...