diff --git a/pkg/common/cartesian.go b/pkg/common/cartesian.go index a4485a0..9cd6065 100644 --- a/pkg/common/cartesian.go +++ b/pkg/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/pkg/common/cartesian_test.go b/pkg/common/cartesian_test.go index 0d9332d..69a6e4e 100644 --- a/pkg/common/cartesian_test.go +++ b/pkg/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) } +