From 6bf905c84bcf7304176eae5ad24168537f9f4b43 Mon Sep 17 00:00:00 2001 From: Ed <3950058+edtan@users.noreply.github.com> Date: Sat, 23 Jan 2021 17:55:54 -0500 Subject: [PATCH] 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 --- act/common/cartesian.go | 2 +- act/common/cartesian_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/act/common/cartesian.go b/act/common/cartesian.go index a4485a01..9cd60655 100644 --- a/act/common/cartesian.go +++ b/act/common/cartesian.go @@ -27,7 +27,7 @@ func cartN(a ...[]interface{}) [][]interface{} { for _, a := range a { c *= len(a) } - if c == 0 { + if c == 0 || len(a) == 0 { return nil } p := make([][]interface{}, c) diff --git a/act/common/cartesian_test.go b/act/common/cartesian_test.go index 0d9332d7..69a6e4e5 100644 --- a/act/common/cartesian_test.go +++ b/act/common/cartesian_test.go @@ -25,4 +25,16 @@ func TestCartesianProduct(t *testing.T) { 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) } +