Skip to content

Commit

Permalink
Add test coverage for pipelinerun resolution edge case
Browse files Browse the repository at this point in the history
We should never hit this case since the state should be caught when the
PipelineRun is created, but it seems weird to a) write the resoultion
code so that it could explode if the creation validation logic changes
and also b) weird to not cover this logic if we're going to add it.

I feel like this might be a slippery slope... We'll see!
  • Loading branch information
bobcatfish authored and knative-prow-robot committed Jan 24, 2019
1 parent 27ae384 commit 538e2b9
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,45 @@ func TestResolvePipelineRun_TaskDoesntExist(t *testing.T) {
}
}

func TestResolvePipelineRun_ResourcesDontExist(t *testing.T) {
tests := []struct {
name string
p *v1alpha1.Pipeline
}{
{
name: "input doesnt exist",
p: tb.Pipeline("pipelines", "namespace", tb.PipelineSpec(
tb.PipelineTask("mytask1", "task",
tb.PipelineTaskInputResource("input1", "git-resource"),
),
)),
},
{
name: "output doesnt exist",
p: tb.Pipeline("pipelines", "namespace", tb.PipelineSpec(
tb.PipelineTask("mytask1", "task",
tb.PipelineTaskOutputResource("input1", "git-resource"),
),
)),
},
}
providedResources := map[string]v1alpha1.PipelineResourceRef{}

getTask := func(name string) (v1alpha1.TaskInterface, error) { return task, nil }
getClusterTask := func(name string) (v1alpha1.TaskInterface, error) { return clustertask, nil }
getResource := func(name string) (*v1alpha1.PipelineResource, error) { return nil, fmt.Errorf("should not get called") }

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := ResolvePipelineRun("pipelinerun", getTask, getClusterTask, getResource, tt.p.Spec.Tasks, providedResources)
if err == nil {
t.Fatalf("Expected error getting non-existent Tasks for Pipeline %s but got none", p.Name)
}
})
}

}

func TestResolveTaskRuns_AllStarted(t *testing.T) {
state := []*ResolvedPipelineRunTask{{
TaskRunName: "pipelinerun-mytask1",
Expand Down

0 comments on commit 538e2b9

Please sign in to comment.