mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
Fix Cartesian product to return empty set if empty set is given (#503)
This fixes #499, where a matrix strategy with only include keys ends up causing multiple builds. This bugs appears to have been introduced in #415, when extra include keys are added in the matrix strategy. The cause seems to be because the CartesianProduct function returns an item with empty keys, instead of return an empty set. Co-authored-by: Ed Tan <edtan@users.noreply.github.com>
This commit is contained in:
parent
19cb4b82ef
commit
6bf905c84b
2 changed files with 13 additions and 1 deletions
|
@ -27,7 +27,7 @@ func cartN(a ...[]interface{}) [][]interface{} {
|
||||||
for _, a := range a {
|
for _, a := range a {
|
||||||
c *= len(a)
|
c *= len(a)
|
||||||
}
|
}
|
||||||
if c == 0 {
|
if c == 0 || len(a) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
p := make([][]interface{}, c)
|
p := make([][]interface{}, c)
|
||||||
|
|
|
@ -25,4 +25,16 @@ func TestCartesianProduct(t *testing.T) {
|
||||||
assert.Contains(v, "baz")
|
assert.Contains(v, "baz")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input = map[string][]interface{}{
|
||||||
|
"foo": {1, 2, 3, 4},
|
||||||
|
"bar": {},
|
||||||
|
"baz": {false, true},
|
||||||
}
|
}
|
||||||
|
output = CartesianProduct(input)
|
||||||
|
assert.Len(output, 0)
|
||||||
|
|
||||||
|
input = map[string][]interface{}{}
|
||||||
|
output = CartesianProduct(input)
|
||||||
|
assert.Len(output, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue