package util import ( "sort" acmapi "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/apis/anthoscertmanager/v1" ) func EqualUnsorted(s1 []string, s2 []string) bool { if len(s1) != len(s2) { return false } s1_2, s2_2 := make([]string, len(s1)), make([]string, len(s2)) copy(s1_2, s1) copy(s2_2, s2) sort.Strings(s1_2) sort.Strings(s2_2) for i, s := range s1_2 { if s != s2_2[i] { return false } } return true } // Test for equal KeyUsage slices even if unsorted func EqualKeyUsagesUnsorted(s1, s2 []acmapi.KeyUsage) bool { if len(s1) != len(s2) { return false } s1_2, s2_2 := make([]string, len(s1)), make([]string, len(s2)) // we may want to implement a sort interface here instead of []byte conversion for i := range s1 { s1_2[i] = string(s1[i]) s2_2[i] = string(s2[i]) } sort.SliceStable(s1_2, func(i, j int) bool { return s1_2[i] < s1_2[j] }) sort.SliceStable(s2_2, func(i, j int) bool { return s2_2[i] < s2_2[j] }) for i, s := range s1_2 { if s != s2_2[i] { return false } } return true }