github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/integration-cli/checker/checker.go (about) 1 // Package checker provides helpers for gotest.tools/assert. 2 // Please remove this package whenever possible. 3 package checker // import "github.com/Prakhar-Agarwal-byte/moby/integration-cli/checker" 4 5 import ( 6 "fmt" 7 8 "gotest.tools/v3/assert" 9 "gotest.tools/v3/assert/cmp" 10 ) 11 12 // Compare defines the interface to compare values 13 type Compare func(x interface{}) assert.BoolOrComparison 14 15 // False checks if the value is false 16 func False() Compare { 17 return func(x interface{}) assert.BoolOrComparison { 18 return !x.(bool) 19 } 20 } 21 22 // True checks if the value is true 23 func True() Compare { 24 return func(x interface{}) assert.BoolOrComparison { 25 return x 26 } 27 } 28 29 // Equals checks if the value is equal to the given value 30 func Equals(y interface{}) Compare { 31 return func(x interface{}) assert.BoolOrComparison { 32 return cmp.Equal(x, y) 33 } 34 } 35 36 // Contains checks if the value contains the given value 37 func Contains(y interface{}) Compare { 38 return func(x interface{}) assert.BoolOrComparison { 39 return cmp.Contains(x, y) 40 } 41 } 42 43 // Not checks if two values are not 44 func Not(c Compare) Compare { 45 return func(x interface{}) assert.BoolOrComparison { 46 r := c(x) 47 switch r := r.(type) { 48 case bool: 49 return !r 50 case cmp.Comparison: 51 return !r().Success() 52 default: 53 panic(fmt.Sprintf("unexpected type %T", r)) 54 } 55 } 56 } 57 58 // DeepEquals checks if two values are equal 59 func DeepEquals(y interface{}) Compare { 60 return func(x interface{}) assert.BoolOrComparison { 61 return cmp.DeepEqual(x, y) 62 } 63 } 64 65 // HasLen checks if the value has the expected number of elements 66 func HasLen(y int) Compare { 67 return func(x interface{}) assert.BoolOrComparison { 68 return cmp.Len(x, y) 69 } 70 } 71 72 // IsNil checks if the value is nil 73 func IsNil() Compare { 74 return func(x interface{}) assert.BoolOrComparison { 75 return cmp.Nil(x) 76 } 77 } 78 79 // GreaterThan checks if the value is greater than the given value 80 func GreaterThan(y int) Compare { 81 return func(x interface{}) assert.BoolOrComparison { 82 return x.(int) > y 83 } 84 }