2023-03-27 12:34:01 +00:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
type filterQueryMatcher repository.SearchQuery
|
|
|
|
|
|
|
|
func (f *filterQueryMatcher) String() string {
|
|
|
|
var filterLists []string
|
2023-10-19 10:19:10 +00:00
|
|
|
for _, filterSlice := range f.SubQueries {
|
2023-03-27 12:34:01 +00:00
|
|
|
var str string
|
|
|
|
for _, filter := range filterSlice {
|
|
|
|
str += "," + (*filterMatcher)(filter).String()
|
|
|
|
}
|
|
|
|
filterLists = append(filterLists, fmt.Sprintf("[%s]", strings.TrimPrefix(str, ",")))
|
|
|
|
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("Filters: %s", strings.Join(filterLists, " "))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *filterQueryMatcher) Matches(x interface{}) bool {
|
|
|
|
other := x.(*repository.SearchQuery)
|
2023-10-19 10:19:10 +00:00
|
|
|
if len(f.SubQueries) != len(other.SubQueries) {
|
2023-03-27 12:34:01 +00:00
|
|
|
return false
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
for filterSliceIdx, filterSlice := range f.SubQueries {
|
|
|
|
if len(filterSlice) != len(other.SubQueries[filterSliceIdx]) {
|
2023-03-27 12:34:01 +00:00
|
|
|
return false
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
for filterIdx, filter := range f.SubQueries[filterSliceIdx] {
|
|
|
|
if !(*filterMatcher)(filter).Matches(other.SubQueries[filterSliceIdx][filterIdx]) {
|
2023-03-27 12:34:01 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *filterQueryMatcher) Got(got interface{}) string {
|
|
|
|
return (*filterQueryMatcher)(got.(*repository.SearchQuery)).String()
|
|
|
|
}
|