CheckerΒΆ
A checker is a core concept of gocheck
and will feel familiar to anyone who has used the python
testtools.Assertions are made on the gocheck.C methods.
c.Check(err, jc.ErrorIsNil)
c.Assert(something, gc.Equals, somethingElse)
The Check
method will cause the test to fail if the checker returns false, but it will continue immediately, causing
the test to fail and will continue with the test.Assert
if it fails will cause the test to stop immediately.
For further discussion, we have the following parts:
c.Assert(observed, checker, args...)
The key checkers in the gocheck
module that juju uses most frequently are:
|
The observed value must be |
|
The observed value must not be |
|
The observed value must be the same type and value as the arg, which is the expected value. |
|
Checks for equality for more complex types like slices, maps, or structures.This is DEPRECATED in favor of the DeepEquals from the |
|
The observed value is expected to be an |
|
A regular expression match where the observed value is a string. |
|
The expected value is an integer, and works happily on nil slices or maps. |
In the juju
project various patterns of testing have emerged over time. These have since been encoded into new and
increasingly more sophisticated checkers.These are found in github.com/juju/testing/checkers
, and are usually imported
with the alias jc
.
The matchers there include (not an exclusive list):
|
Just an easier way to say |
|
Observed value must be false. |
|
For integer or float types. |
|
For integer or float types. |
|
Obtained is expected to be a string or a |
|
The same as |
|
Obtained is a string or |
|
Works the same way as the |
|
Obtained and expected are slices of the same type, the checker makes sure that the values in one are in the other.They do not have the be in the same order. |
|
The arg is expected to be |
|
Obtained is a string or |
|
Works similarly to |
|
Also works with a string or |