-
Notifications
You must be signed in to change notification settings - Fork 134
/
matchers.go
45 lines (40 loc) · 1001 Bytes
/
matchers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package schedulermocks
import (
"sort"
"strings"
)
type Stringer interface {
String() string
}
type SliceMatcher[T Stringer] struct {
Expected []T
}
// Matches
// Matches input against provided expected input
// This matching ignores the input ordering, so args don't need to be passed in a known order
func (s SliceMatcher[T]) Matches(x interface{}) bool {
inputs, ok := x.([]T)
if !ok {
return false
}
expected := s.Expected
if len(inputs) != len(expected) {
return false
}
sort.Slice(inputs, func(i, j int) bool {
return strings.Compare(inputs[i].String(), inputs[j].String()) < 0
})
sort.Slice(expected, func(i, j int) bool {
return strings.Compare(expected[i].String(), expected[j].String()) < 0
})
for i, inputValue := range inputs {
if inputValue.String() != expected[i].String() {
return false
}
}
return true
}
// String describes what the matcher matches.
func (s SliceMatcher[T]) String() string {
return "checks provided matches expected uuid list"
}