-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stub check calls without order. #132
Stub check calls without order. #132
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a small tweak, but otherwise I think the functionality is quite useful.
stub.go
Outdated
// This method explicitly does not check if the calls were made in order, just | ||
// whether they have been made. | ||
func (f *Stub) CheckCallsUnordered(c *gc.C, expected []StubCall) { | ||
c.Check(len(f.calls), gc.Equals, len(expected)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will do the wrong thing if you ask about:
[a, b, c, c]
And you actually get
[a, b, b, c]
Because in both cases the len is correct, and all of a, b, c was called.
Just doing:
calls = f.calls[:]
removeFound = func(call StubCall) bool {
foundIdx := -1
for idx, madeCall := range calls {
if reflect.DeepEqual(call, madeCall) {
foundIdx = idx
break
}
}
if foundIdx == -1 {
return false
}
calls = append(calls[:foundIdx], calls[foundIdx+1]...)
return true
}
The other nice thing about this is when you're done with the loop, you can do
c.Check(calls, gc.DeepEquals, []StubCall{})
which should print out any calls that happened that you weren't expecting.
Oh, good call \o/ |
|
Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju-testing |
Build failed: Tests failed |
Failure unrelated to my change... Parsing meta tags from https://gopkg.in/mgo.v2?go-get=1 (status code 200) get "gopkg.in/mgo.v2": found meta tag get.metaImport{Prefix:"gopkg.in/mgo.v2", VCS:"git", RepoRoot:"https://gopkg.in/mgo.v2"} at https://gopkg.in/mgo.v2?go-get=1 2018-01-10 23:40:49 WARNING juju.testing mgo.go:218 failed to start mongo: exec: "/usr/local/bin/mongod": stat /usr/local/bin/mongod: no such file or directory --- FAIL: Test (0.00s)
FAIL FAIL github.com/juju/testing 0.024s |
|
Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju-testing |
Build failed: Tests failed |
All current methods on testing Stub assume that the order of calls matters.
However, there are situations where we only care about the fact that the calls where made, not in what order they were made. For example, intermittent failures in https://bugs.launchpad.net/juju/+bug/1742222 specifically occur because we expect the calls to have been made but the calls in asynchronous system can be made in any order.
This PR adds a method that allows to check that the expected calls where made, not when they were made.