mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
prepare for eg on waitAndAssert
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
@@ -1,24 +1,78 @@
|
||||
// Package checker provides Docker specific implementations of the go-check.Checker interface.
|
||||
// Package checker provides helpers for gotest.tools/assert.
|
||||
// Please remove this package whenever possible.
|
||||
package checker // import "github.com/docker/docker/integration-cli/checker"
|
||||
|
||||
import (
|
||||
"github.com/go-check/check"
|
||||
"github.com/vdemeester/shakers"
|
||||
"fmt"
|
||||
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
// As a commodity, we bring all check.Checker variables into the current namespace to avoid having
|
||||
// to think about check.X versus checker.X.
|
||||
var (
|
||||
DeepEquals = check.DeepEquals
|
||||
HasLen = check.HasLen
|
||||
IsNil = check.IsNil
|
||||
Matches = check.Matches
|
||||
Not = check.Not
|
||||
NotNil = check.NotNil
|
||||
type Compare func(x interface{}) assert.BoolOrComparison
|
||||
|
||||
Contains = shakers.Contains
|
||||
Equals = shakers.Equals
|
||||
False = shakers.False
|
||||
GreaterThan = shakers.GreaterThan
|
||||
True = shakers.True
|
||||
)
|
||||
func False() Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return !x.(bool)
|
||||
}
|
||||
}
|
||||
|
||||
func True() Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
func Equals(y interface{}) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return cmp.Equal(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func Contains(y interface{}) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return cmp.Contains(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func Not(c Compare) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
r := c(x)
|
||||
switch r := r.(type) {
|
||||
case bool:
|
||||
return !r
|
||||
case cmp.Comparison:
|
||||
return !r().Success()
|
||||
default:
|
||||
panic(fmt.Sprintf("unexpected type %T", r))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func DeepEquals(y interface{}) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return cmp.DeepEqual(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func HasLen(y int) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return cmp.Len(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func IsNil() Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return cmp.Nil(x)
|
||||
}
|
||||
}
|
||||
|
||||
func GreaterThan(y int) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return x.(int) > y
|
||||
}
|
||||
}
|
||||
|
||||
func NotNil() Compare {
|
||||
return Not(IsNil())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user