Skip to content

Commit

Permalink
adding unit tests
Browse files Browse the repository at this point in the history
1) reconciler with invalid dag graph must result in error
2) pipeline must result in timeout if its runtime exceeds its spec.Timeout
  • Loading branch information
pritidesai authored and tekton-robot committed Jun 24, 2020
1 parent 7575000 commit c2d3ea6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ func TestReconcile_InvalidPipelineRuns(t *testing.T) {
tb.PipelineParamSpec("some-param", v1beta1.ParamTypeString),
tb.PipelineTask("some-task", "a-task-that-needs-params")),
)),
tb.PipelineRun("pipeline-invalid-dag-graph", tb.PipelineRunNamespace("foo"), tb.PipelineRunSpec("", tb.PipelineRunPipelineSpec(
tb.PipelineTask("dag-task-1", "dag-task-1", tb.RunAfter("dag-task-1")),
))),
}
d := test.Data{
Tasks: ts,
Expand Down Expand Up @@ -505,6 +508,10 @@ func TestReconcile_InvalidPipelineRuns(t *testing.T) {
name: "invalid-pipeline-run-missing-params-shd-stop-reconciling",
pipelineRun: prs[11],
reason: ReasonParameterMissing,
}, {
name: "invalid-pipeline-with-invalid-dag-graph",
pipelineRun: prs[12],
reason: ReasonInvalidGraph,
},
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -1450,6 +1451,29 @@ func TestGetPipelineConditionStatus(t *testing.T) {
}
}

// pipeline should result in timeout if its runtime exceeds its spec.Timeout based on its status.Timeout
func TestGetPipelineConditionStatus_PipelineTimeouts(t *testing.T) {
d, err := DagFromState(oneFinishedState)
if err != nil {
t.Fatalf("Unexpected error while buildig DAG for state %v: %v", oneFinishedState, err)
}
pr := &v1beta1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{Name: "pipelinerun-no-tasks-started"},
Spec: v1beta1.PipelineRunSpec{
Timeout: &metav1.Duration{Duration: 1 * time.Minute},
},
Status: v1beta1.PipelineRunStatus{
PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
StartTime: &metav1.Time{Time: time.Now().Add(-2 * time.Minute)},
},
},
}
c := GetPipelineConditionStatus(pr, oneFinishedState, zap.NewNop().Sugar(), d)
if c.Status != corev1.ConditionFalse && c.Reason != v1beta1.PipelineRunReasonTimedOut.String() {
t.Fatalf("Expected to get status %s but got %s for state %v", corev1.ConditionFalse, c.Status, oneFinishedState)
}
}

func TestGetResourcesFromBindings(t *testing.T) {
pr := tb.PipelineRun("pipelinerun", tb.PipelineRunSpec("pipeline",
tb.PipelineRunResourceBinding("git-resource", tb.PipelineResourceBindingRef("sweet-resource")),
Expand Down

0 comments on commit c2d3ea6

Please sign in to comment.