2019-08-09 06:41:13 -04:00
|
|
|
// Package checker provides helpers for gotest.tools/assert.
|
|
|
|
// Please remove this package whenever possible.
|
2018-02-05 16:05:59 -05:00
|
|
|
package checker // import "github.com/docker/docker/integration-cli/checker"
|
2015-09-03 18:55:52 -04:00
|
|
|
|
|
|
|
import (
|
2019-08-09 06:41:13 -04:00
|
|
|
"fmt"
|
2015-09-03 18:55:52 -04:00
|
|
|
|
2019-08-09 06:41:13 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
"gotest.tools/assert/cmp"
|
2015-10-17 07:41:44 -04:00
|
|
|
)
|
2019-08-09 06:41:13 -04:00
|
|
|
|
2019-09-19 03:50:42 -04:00
|
|
|
// Compare defines the interface to compare values
|
2019-08-09 06:41:13 -04:00
|
|
|
type Compare func(x interface{}) assert.BoolOrComparison
|
|
|
|
|
2019-09-19 03:50:42 -04:00
|
|
|
// False checks if the value is false
|
2019-08-09 06:41:13 -04:00
|
|
|
func False() Compare {
|
|
|
|
return func(x interface{}) assert.BoolOrComparison {
|
|
|
|
return !x.(bool)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 03:50:42 -04:00
|
|
|
// True checks if the value is true
|
2019-08-09 06:41:13 -04:00
|
|
|
func True() Compare {
|
|
|
|
return func(x interface{}) assert.BoolOrComparison {
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 03:50:42 -04:00
|
|
|
// Equals checks if the value is equal to the given value
|
2019-08-09 06:41:13 -04:00
|
|
|
func Equals(y interface{}) Compare {
|
|
|
|
return func(x interface{}) assert.BoolOrComparison {
|
|
|
|
return cmp.Equal(x, y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 03:50:42 -04:00
|
|
|
// Contains checks if the value contains the given value
|
2019-08-09 06:41:13 -04:00
|
|
|
func Contains(y interface{}) Compare {
|
|
|
|
return func(x interface{}) assert.BoolOrComparison {
|
|
|
|
return cmp.Contains(x, y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 03:50:42 -04:00
|
|
|
// Not checks if two values are not
|
2019-08-09 06:41:13 -04:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 03:50:42 -04:00
|
|
|
// DeepEquals checks if two values are equal
|
2019-08-09 06:41:13 -04:00
|
|
|
func DeepEquals(y interface{}) Compare {
|
|
|
|
return func(x interface{}) assert.BoolOrComparison {
|
|
|
|
return cmp.DeepEqual(x, y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 03:50:42 -04:00
|
|
|
// DeepEquals compares if two values are deepequal
|
2019-08-09 06:41:13 -04:00
|
|
|
func HasLen(y int) Compare {
|
|
|
|
return func(x interface{}) assert.BoolOrComparison {
|
|
|
|
return cmp.Len(x, y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 03:50:42 -04:00
|
|
|
// DeepEquals checks if the given value is nil
|
2019-08-09 06:41:13 -04:00
|
|
|
func IsNil() Compare {
|
|
|
|
return func(x interface{}) assert.BoolOrComparison {
|
|
|
|
return cmp.Nil(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 03:50:42 -04:00
|
|
|
// GreaterThan checks if the value is greater than the given value
|
2019-08-09 06:41:13 -04:00
|
|
|
func GreaterThan(y int) Compare {
|
|
|
|
return func(x interface{}) assert.BoolOrComparison {
|
|
|
|
return x.(int) > y
|
|
|
|
}
|
|
|
|
}
|