Visitar URL original
fix: skip resource depends on skipped source by olblak · Pull Request #9916 · updatecli/updatecli · GitHub
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
5 changes: 5 additions & 0 deletions pkg/core/pipeline/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func (p *Pipeline) shouldSkipResource(leaf *Node, depsResults map[string]*Node)
if dependencyResult.Category == conditionCategory && dependencyResult.Result != result.SUCCESS {
return true
}
// A skipped source doesn't provide any value, so running its dependents
// would have them consume an empty source input.
if dependencyResult.Category == sourceCategory && dependencyResult.Result == result.SKIPPED {
return true
}
if dependencyResult.Result == result.FAILURE {
// And operator but dep is failed
return true
Expand Down
91 changes: 91 additions & 0 deletions pkg/core/pipeline/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/updatecli/updatecli/pkg/core/result"
)

func TestExtractDepsFromTemplate(t *testing.T) {
Expand Down Expand Up @@ -46,3 +47,93 @@ func TestExtractDepsFromTemplate(t *testing.T) {
})
}
}

func TestShouldSkipResource(t *testing.T) {
testdata := []struct {
Name string
Leaf Node
DepsResults map[string]*Node
ExpectedResult bool
}{
{
Name: "target depending on a successful source runs",
Leaf: Node{
ID: "target#mytarget",
Category: targetCategory,
DependsOn: []Dependency{{ID: "source#mysource", Operator: andBooleanOperator}},
},
DepsResults: map[string]*Node{
"source#mysource": {ID: "source#mysource", Category: sourceCategory, Result: result.SUCCESS},
},
ExpectedResult: false,
},
{
// A skipped source has no value to provide, so its dependents would otherwise
// consume an empty source input.
Name: "target depending on a skipped source is skipped",
Leaf: Node{
ID: "target#mytarget",
Category: targetCategory,
DependsOn: []Dependency{{ID: "source#mysource", Operator: andBooleanOperator}},
},
DepsResults: map[string]*Node{
"source#mysource": {ID: "source#mysource", Category: sourceCategory, Result: result.SKIPPED},
},
ExpectedResult: true,
},
{
Name: "condition depending on a skipped source is skipped",
Leaf: Node{
ID: "condition#mycondition",
Category: conditionCategory,
DependsOn: []Dependency{{ID: "source#mysource", Operator: andBooleanOperator}},
},
DepsResults: map[string]*Node{
"source#mysource": {ID: "source#mysource", Category: sourceCategory, Result: result.SKIPPED},
},
ExpectedResult: true,
},
{
Name: "target depending on a failed source is skipped",
Leaf: Node{
ID: "target#mytarget",
Category: targetCategory,
DependsOn: []Dependency{{ID: "source#mysource", Operator: andBooleanOperator}},
},
DepsResults: map[string]*Node{
"source#mysource": {ID: "source#mysource", Category: sourceCategory, Result: result.FAILURE},
},
ExpectedResult: true,
},
{
// A skipped target only means it had nothing to change, which mustn't stop
// the resources depending on it.
Name: "target depending on a skipped target runs",
Leaf: Node{
ID: "target#mytarget",
Category: targetCategory,
DependsOn: []Dependency{{ID: "target#myothertarget", Operator: andBooleanOperator}},
},
DepsResults: map[string]*Node{
"target#myothertarget": {ID: "target#myothertarget", Category: targetCategory, Result: result.SKIPPED},
},
ExpectedResult: false,
},
{
Name: "resource without any dependency runs",
Leaf: Node{
ID: "target#mytarget",
Category: targetCategory,
},
ExpectedResult: false,
},
}

p := Pipeline{}

for _, tt := range testdata {
t.Run(tt.Name, func(t *testing.T) {
require.Equal(t, tt.ExpectedResult, p.shouldSkipResource(&tt.Leaf, tt.DepsResults))
})
}
}
Loading