github.com/nektos/act@v0.2.63/pkg/common/cartesian_test.go (about)

     1  package common
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestCartesianProduct(t *testing.T) {
    10  	assert := assert.New(t)
    11  	input := map[string][]interface{}{
    12  		"foo": {1, 2, 3, 4},
    13  		"bar": {"a", "b", "c"},
    14  		"baz": {false, true},
    15  	}
    16  
    17  	output := CartesianProduct(input)
    18  	assert.Len(output, 24)
    19  
    20  	for _, v := range output {
    21  		assert.Len(v, 3)
    22  
    23  		assert.Contains(v, "foo")
    24  		assert.Contains(v, "bar")
    25  		assert.Contains(v, "baz")
    26  	}
    27  
    28  	input = map[string][]interface{}{
    29  		"foo": {1, 2, 3, 4},
    30  		"bar": {},
    31  		"baz": {false, true},
    32  	}
    33  	output = CartesianProduct(input)
    34  	assert.Len(output, 0)
    35  
    36  	input = map[string][]interface{}{}
    37  	output = CartesianProduct(input)
    38  	assert.Len(output, 0)
    39  }