util: Rename SortedStrSliceCompare and move to util package
This commit is contained in:
@@ -270,27 +270,3 @@ func GetGID(group string) (int, error) {
|
||||
|
||||
return -1, errwrap.Wrapf(err, "group lookup error (%s)", group)
|
||||
}
|
||||
|
||||
// StrSortedSliceCompare takes two lists of strings and returns whether or not
|
||||
// they are equivalent. It will return nil if both sets contain the same
|
||||
// elements, regardless of order, and an error if they do not.
|
||||
func StrSortedSliceCompare(a, b []string) error {
|
||||
if len(a) != len(b) {
|
||||
return fmt.Errorf("slices have different lengths: %d vs %d", len(a), len(b))
|
||||
}
|
||||
|
||||
// make a copy of each to sort, so we don't reorder the inputs
|
||||
x := make([]string, len(a))
|
||||
y := make([]string, len(b))
|
||||
copy(x, a)
|
||||
copy(y, b)
|
||||
|
||||
sort.Strings(x)
|
||||
sort.Strings(y)
|
||||
for i := range x {
|
||||
if x[i] != y[i] {
|
||||
return fmt.Errorf("values do not match: %s vs %s", x[i], y[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user