Skip to content

Commit

Permalink
Add a test in target_test
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe committed Oct 25, 2022
1 parent 4a5f016 commit 0555d58
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions pkg/engine/lifecycletest/target_test.go
Expand Up @@ -165,21 +165,24 @@ func TestUpdateTarget(t *testing.T) {
t.Run(fmt.Sprintf("update %v", subset), func(t *testing.T) {
t.Parallel()

updateSpecificTargets(t, subset, false /*targetDependents*/)
updateSpecificTargets(t, subset, nil, false /*targetDependents*/, -1)
})
}
}

updateSpecificTargets(t, []string{"A"}, false /*targetDependents*/)
updateSpecificTargets(t, []string{"A"}, nil, false /*targetDependents*/, -1)

// Also update a target that doesn't exist to make sure we don't crash or otherwise go off the rails.
updateInvalidTarget(t)

// We want to check that targetDependents is respected
updateSpecificTargets(t, []string{"C"}, true /*targetDependents*/)
updateSpecificTargets(t, []string{"C"}, nil, true /*targetDependents*/, -1)

updateSpecificTargets(t, nil, []string{"**C**"}, false, 1)
updateSpecificTargets(t, nil, []string{"**providers:pkgA**"}, false, 3)
}

func updateSpecificTargets(t *testing.T, targets []string, targetDependents bool) {
func updateSpecificTargets(t *testing.T, targets, globTargets []string, targetDependents bool, expectedUpdates int) {
// A
// _________|_________
// B C D
Expand Down Expand Up @@ -219,13 +222,13 @@ func updateSpecificTargets(t *testing.T, targets []string, targetDependents bool
p.Options.Host = deploytest.NewPluginHost(nil, nil, program, loaders...)
p.Options.TargetDependents = targetDependents

updateTargets := []resource.URN{}
updateTargets := globTargets
for _, target := range targets {
updateTargets = append(updateTargets,
pickURN(t, urns, complexTestDependencyGraphNames, target))
string(pickURN(t, urns, complexTestDependencyGraphNames, target)))
}

p.Options.UpdateTargets = deploy.NewUrnTargetsFromUrns(updateTargets)
p.Options.UpdateTargets = deploy.NewUrnTargets(updateTargets)
t.Logf("Updating targets: %v", updateTargets)

p.Steps = []TestStep{{
Expand Down Expand Up @@ -278,7 +281,9 @@ func updateSpecificTargets(t *testing.T, targets []string, targetDependents bool
for _, target := range p.Options.UpdateTargets.Literals() {
assert.NotContains(t, sames, target)
}

if expectedUpdates > -1 {
assert.Equal(t, expectedUpdates, len(updated), "Updates = %#v", updated)
}
return res
},
}}
Expand Down

0 comments on commit 0555d58

Please sign in to comment.