1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration-cli/checker/checker.go
Sebastiaan van Stijn f4c172e6b9
integration-cli: fix golint (copy/paste whoops)
These were accidentally wrong due to a sloppy copy/paste issue. Interestingly,
CI passed on the PR that added it (6397dd4d31),
possibly because of this issue, it stopped linting?

    WARN [runner/golint] Golint: can't lint 4 files: no file name for file &{Doc:<nil> Package:23044677 Name:quota Decls:[0xc02cc3fa40 0xc02cc3fac0 0xc02cc3fb40 0xc02cc3fbc0 0xc02cc62ab0 0xc02cc62c00] Scope:scope 0xc02cc5c340 {
     	var ErrQuotaNotSupported
     	type errQuotaNotSupported
     }
     Imports:[0xc02cc62930] Unresolved:[errdefs nil string] Comments:[0xc02cbc9ae0 0xc02cbc9c60]}

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-30 14:59:00 +02:00

84 lines
1.9 KiB
Go

// 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 (
"fmt"
"gotest.tools/assert"
"gotest.tools/assert/cmp"
)
// Compare defines the interface to compare values
type Compare func(x interface{}) assert.BoolOrComparison
// False checks if the value is false
func False() Compare {
return func(x interface{}) assert.BoolOrComparison {
return !x.(bool)
}
}
// True checks if the value is true
func True() Compare {
return func(x interface{}) assert.BoolOrComparison {
return x
}
}
// Equals checks if the value is equal to the given value
func Equals(y interface{}) Compare {
return func(x interface{}) assert.BoolOrComparison {
return cmp.Equal(x, y)
}
}
// Contains checks if the value contains the given value
func Contains(y interface{}) Compare {
return func(x interface{}) assert.BoolOrComparison {
return cmp.Contains(x, y)
}
}
// Not checks if two values are not
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))
}
}
}
// DeepEquals checks if two values are equal
func DeepEquals(y interface{}) Compare {
return func(x interface{}) assert.BoolOrComparison {
return cmp.DeepEqual(x, y)
}
}
// HasLen checks if the value has the expected number of elements
func HasLen(y int) Compare {
return func(x interface{}) assert.BoolOrComparison {
return cmp.Len(x, y)
}
}
// IsNil checks if the value is nil
func IsNil() Compare {
return func(x interface{}) assert.BoolOrComparison {
return cmp.Nil(x)
}
}
// GreaterThan checks if the value is greater than the given value
func GreaterThan(y int) Compare {
return func(x interface{}) assert.BoolOrComparison {
return x.(int) > y
}
}