Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions pkg/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@

// GetMatrixes returns the matrix cross product
// It skips includes and hard fails excludes for non-existing keys
//
//nolint:gocyclo
func (j *Job) GetMatrixes() ([]map[string]interface{}, error) {
matrixes := make([]map[string]interface{}, 0)
if j.Strategy != nil {
Expand All @@ -406,31 +404,11 @@
case []interface{}:
for _, i := range t {
i := i.(map[string]interface{})
extraInclude := true
for k := range i {
if _, ok := m[k]; ok {
includes = append(includes, i)
extraInclude = false
break
}
}
if extraInclude {
extraIncludes = append(extraIncludes, i)
}
includes = append(includes, i)

Check warning on line 407 in pkg/model/workflow.go

View check run for this annotation

Codecov / codecov/patch

pkg/model/workflow.go#L407

Added line #L407 was not covered by tests
}
case interface{}:
v := v.(map[string]interface{})
extraInclude := true
for k := range v {
if _, ok := m[k]; ok {
includes = append(includes, v)
extraInclude = false
break
}
}
if extraInclude {
extraIncludes = append(extraIncludes, v)
}
includes = append(includes, v)
}
}
delete(m, "include")
Expand Down
35 changes: 31 additions & 4 deletions pkg/model/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)

func TestReadWorkflow_StringEvent(t *testing.T) {
Expand Down Expand Up @@ -367,10 +369,9 @@ func TestReadWorkflow_Strategy(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, matrixes,
[]map[string]interface{}{
{"datacenter": "site-c", "node-version": "14.x", "site": "staging"},
{"datacenter": "site-c", "node-version": "16.x", "site": "staging"},
{"datacenter": "site-d", "node-version": "16.x", "site": "staging"},
{"php-version": 5.4},
{"datacenter": "site-c", "node-version": "14.x", "site": "staging", "php-version": 5.4},
{"datacenter": "site-c", "node-version": "16.x", "site": "staging", "php-version": 5.4},
{"datacenter": "site-d", "node-version": "16.x", "site": "staging", "php-version": 5.4},
{"datacenter": "site-a", "node-version": "10.x", "site": "prod"},
{"datacenter": "site-b", "node-version": "12.x", "site": "dev"},
},
Expand All @@ -394,6 +395,32 @@ func TestReadWorkflow_Strategy(t *testing.T) {
assert.Equal(t, job.Strategy.FailFast, false)
}

func TestMatrixOnlyIncludes(t *testing.T) {
matrix := map[string][]interface{}{
"include": []interface{}{
map[string]interface{}{"a": "1", "b": "2"},
map[string]interface{}{"a": "3", "b": "4"},
},
}
rN := yaml.Node{}
err := rN.Encode(matrix)
require.NoError(t, err, "encoding matrix should succeed")
job := &Job{
Strategy: &Strategy{
RawMatrix: rN,
},
}
assert.Equal(t, job.Matrix(), matrix)
matrixes, err := job.GetMatrixes()
require.NoError(t, err)
assert.Equal(t, matrixes,
[]map[string]interface{}{
{"a": "1", "b": "2"},
{"a": "3", "b": "4"},
},
)
}

func TestStep_ShellCommand(t *testing.T) {
tests := []struct {
shell string
Expand Down