mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-21 04:30:37 +00:00
Fix tests and pipeline (#732)
* fix pipeline * use EqualStringSlice to compare slices in tests * full test coverage * tests: wait for mysql/postgres to sync ...
This commit is contained in:
@@ -30,3 +30,29 @@ func DedupStrings(list []string) []string {
|
||||
}
|
||||
return newList
|
||||
}
|
||||
|
||||
// EqualStringSlice compare two string slices if they have equal values independ of how they are sorted
|
||||
func EqualStringSlice(l1, l2 []string) bool {
|
||||
if len(l1) != len(l2) {
|
||||
return false
|
||||
}
|
||||
|
||||
m1 := sliceToCountMap(l1)
|
||||
m2 := sliceToCountMap(l2)
|
||||
|
||||
for k, v := range m1 {
|
||||
if m2[k] != v {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func sliceToCountMap(list []string) map[string]int {
|
||||
m := make(map[string]int)
|
||||
for i := range list {
|
||||
m[list[i]]++
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
@@ -46,3 +46,31 @@ func TestDedupStrings(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualStringSlice(t *testing.T) {
|
||||
tests := []struct {
|
||||
in1 []string
|
||||
in2 []string
|
||||
out bool
|
||||
}{{
|
||||
in1: []string{"", "ab", "12", "ab"},
|
||||
in2: []string{"12", "ab"},
|
||||
out: false,
|
||||
}, {
|
||||
in1: nil,
|
||||
in2: nil,
|
||||
out: true,
|
||||
}, {
|
||||
in1: []string{"AA", "AA", "2", " "},
|
||||
in2: []string{"2", "AA", " ", "AA"},
|
||||
out: true,
|
||||
}, {
|
||||
in1: []string{"AA", "AA", "2", " "},
|
||||
in2: []string{"2", "2", " ", "AA"},
|
||||
out: false,
|
||||
}}
|
||||
|
||||
for _, tc := range tests {
|
||||
assert.EqualValues(t, tc.out, EqualStringSlice(tc.in1, tc.in2), "could not correctly process input: '%#v', %#v", tc.in1, tc.in2)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user