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
|
|
|
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
"gotest.tools/v3/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-30 08:59:00 -04:00
|
|
|
// HasLen checks if the value has the expected number of elements
|
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-30 08:59:00 -04:00
|
|
|
// IsNil checks if the 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
|
|
|
|
}
|
|
|
|
}
|