1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/vendor/github.com/vdemeester/shakers/bool.go

47 lines
882 B
Go
Raw Normal View History

package shakers
import (
"github.com/go-check/check"
)
// True checker verifies the obtained value is true
//
// c.Assert(myBool, True)
//
var True check.Checker = &boolChecker{
&check.CheckerInfo{
Name: "True",
Params: []string{"obtained"},
},
true,
}
// False checker verifies the obtained value is false
//
// c.Assert(myBool, False)
//
var False check.Checker = &boolChecker{
&check.CheckerInfo{
Name: "False",
Params: []string{"obtained"},
},
false,
}
type boolChecker struct {
*check.CheckerInfo
expected bool
}
func (checker *boolChecker) Check(params []interface{}, names []string) (bool, string) {
return is(checker.expected, params[0])
}
func is(expected bool, obtained interface{}) (bool, string) {
obtainedBool, ok := obtained.(bool)
if !ok {
return false, "obtained value must be a bool."
}
return obtainedBool == expected, ""
}