Skip to content

Commit

Permalink
Make sure required PVC is created in reconciler test 👶
Browse files Browse the repository at this point in the history
When I was working on #1417 (which added the ability to create PVCs for
the Volume Resource and has since been abandoned) I was surprised to
realize that the reconciler test for the PipelineRun controller doesn't
verify that the PVC has been created. It does make sure its attached and
this is covered by the end to end tests that wouldn't work without it,
but I thought it made sense to test here too since we can.
  • Loading branch information
bobcatfish authored and tekton-robot committed Oct 31, 2019
1 parent 49de48b commit 3a458d1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ func TestReconcile(t *testing.T) {
if _, exists := reconciledRun.Status.TaskRuns["test-pipeline-run-success-unit-test-cluster-task-78c5n"]; !exists {
t.Errorf("Expected PipelineRun status to include TaskRun status but was %v", reconciledRun.Status.TaskRuns)
}

// A PVC should have been created to deal with output -> input linking
ensurePVCCreated(t, clients, expectedTaskRun.GetPipelineRunPVCName(), "foo")
}

func TestReconcile_InvalidPipelineRuns(t *testing.T) {
Expand Down Expand Up @@ -1561,3 +1564,20 @@ func makeExpectedTr(condName, ccName string) *v1alpha1.TaskRun {
),
)
}

func ensurePVCCreated(t *testing.T, clients test.Clients, name, namespace string) {
t.Helper()
_, err := clients.Kube.CoreV1().PersistentVolumeClaims(namespace).Get(name, metav1.GetOptions{})
if err != nil {
t.Errorf("Expected PVC %s to be created for VolumeResource but did not exist", name)
}
pvcCreated := false
for _, a := range clients.Kube.Actions() {
if a.GetVerb() == "create" && a.GetResource().Resource == "persistentvolumeclaims" {
pvcCreated = true
}
}
if !pvcCreated {
t.Errorf("Expected to see volume resource PVC created but didn't")
}
}

0 comments on commit 3a458d1

Please sign in to comment.