Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the test context in Reconcile tests #3285

Merged
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
7 changes: 4 additions & 3 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func getPipelineRunController(t *testing.T, d test.Data) (test.Assets, func()) {
Clients: c,
Informers: informers,
Recorder: controller.GetEventRecorder(ctx).(*record.FakeRecorder),
Ctx: ctx,
}, cancel
}

Expand Down Expand Up @@ -747,7 +748,7 @@ func TestReconcile_InvalidPipelineRunNames(t *testing.T) {
defer cancel()
c := testAssets.Controller

err := c.Reconciler.Reconcile(context.Background(), tc.pipelineRun)
err := c.Reconciler.Reconcile(testAssets.Ctx, tc.pipelineRun)
// No reason to keep reconciling something that doesnt or can't exist
if err != nil {
t.Errorf("Did not expect to see error when reconciling invalid PipelineRun but saw %q", err)
Expand Down Expand Up @@ -1244,7 +1245,7 @@ func TestReconcileCancelledFailsTaskRunCancellation(t *testing.T) {
return true, nil, fmt.Errorf("i'm sorry Dave, i'm afraid i can't do that")
})

err := c.Reconciler.Reconcile(context.Background(), "foo/test-pipeline-fails-to-cancel")
err := c.Reconciler.Reconcile(testAssets.Ctx, "foo/test-pipeline-fails-to-cancel")
if err == nil {
t.Errorf("Expected to see error returned from reconcile after failing to cancel TaskRun but saw none!")
}
Expand Down Expand Up @@ -3942,7 +3943,7 @@ func (prt PipelineRunTest) reconcileRun(namespace, pipelineRunName string, wantE
c := prt.TestAssets.Controller
clients := prt.TestAssets.Clients

reconcileError := c.Reconciler.Reconcile(context.Background(), namespace+"/"+pipelineRunName)
reconcileError := c.Reconciler.Reconcile(prt.TestAssets.Ctx, namespace+"/"+pipelineRunName)
if permanentError {
// When a PipelineRun is invalid and can't run, we expect a permanent error that will
// tell the Reconciler to not keep trying to reconcile.
Expand Down
27 changes: 14 additions & 13 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ func getTaskRunController(t *testing.T, d test.Data) (test.Assets, func()) {
Clients: c,
Informers: informers,
Recorder: controller.GetEventRecorder(ctx).(*record.FakeRecorder),
Ctx: ctx,
}, cancel
}

Expand Down Expand Up @@ -483,7 +484,7 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) {
c := testAssets.Controller
clients := testAssets.Clients

if err := c.Reconciler.Reconcile(context.Background(), getRunName(tc.taskRun)); err != nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(tc.taskRun)); err != nil {
t.Errorf("expected no error. Got error %v", err)
}
if len(clients.Kube.Actions()) == 0 {
Expand Down Expand Up @@ -668,7 +669,7 @@ func TestReconcile_FeatureFlags(t *testing.T) {
}); err != nil {
t.Fatal(err)
}
if err := c.Reconciler.Reconcile(context.Background(), getRunName(tc.taskRun)); err != nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(tc.taskRun)); err != nil {
t.Errorf("expected no error. Got error %v", err)
}
if len(clients.Kube.Actions()) == 0 {
Expand Down Expand Up @@ -753,7 +754,7 @@ func TestReconcile_CloudEvents(t *testing.T) {
t.Fatal(err)
}

if err := c.Reconciler.Reconcile(context.Background(), getRunName(taskRun)); err != nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(taskRun)); err != nil {
t.Errorf("expected no error. Got error %v", err)
}
if len(clients.Kube.Actions()) == 0 {
Expand Down Expand Up @@ -1458,7 +1459,7 @@ func TestReconcile(t *testing.T) {
t.Fatal(err)
}

if err := c.Reconciler.Reconcile(context.Background(), getRunName(tc.taskRun)); err != nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(tc.taskRun)); err != nil {
t.Errorf("expected no error. Got error %v", err)
}
if len(clients.Kube.Actions()) == 0 {
Expand Down Expand Up @@ -1616,7 +1617,7 @@ func TestReconcileInvalidTaskRuns(t *testing.T) {
defer cancel()
c := testAssets.Controller
clients := testAssets.Clients
reconcileErr := c.Reconciler.Reconcile(context.Background(), getRunName(tc.taskRun))
reconcileErr := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(tc.taskRun))

// When a TaskRun is invalid and can't run, we return a permanent error because
// a regular error will tell the Reconciler to keep trying to reconcile; instead we want to stop
Expand Down Expand Up @@ -1676,7 +1677,7 @@ func TestReconcilePodFetchError(t *testing.T) {
return true, nil, errors.New("induce failure fetching pods")
})

if err := c.Reconciler.Reconcile(context.Background(), getRunName(taskRun)); err == nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(taskRun)); err == nil {
t.Fatal("expected error when reconciling a Task for which we couldn't get the corresponding Pod but got nil")
}
}
Expand Down Expand Up @@ -1734,7 +1735,7 @@ func TestReconcilePodUpdateStatus(t *testing.T) {
c := testAssets.Controller
clients := testAssets.Clients

if err := c.Reconciler.Reconcile(context.Background(), getRunName(taskRun)); err != nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(taskRun)); err != nil {
t.Fatalf("Unexpected error when Reconcile() : %v", err)
}
newTr, err := clients.Pipeline.TektonV1beta1().TaskRuns(taskRun.Namespace).Get(taskRun.Name, metav1.GetOptions{})
Expand Down Expand Up @@ -1770,7 +1771,7 @@ func TestReconcilePodUpdateStatus(t *testing.T) {
// lister cache is update to reflect the result of the previous Reconcile.
testAssets.Informers.TaskRun.Informer().GetIndexer().Add(newTr)

if err := c.Reconciler.Reconcile(context.Background(), getRunName(taskRun)); err != nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(taskRun)); err != nil {
t.Fatalf("Unexpected error when Reconcile(): %v", err)
}

Expand Down Expand Up @@ -1820,7 +1821,7 @@ func TestReconcileOnCompletedTaskRun(t *testing.T) {
c := testAssets.Controller
clients := testAssets.Clients

if err := c.Reconciler.Reconcile(context.Background(), getRunName(taskRun)); err != nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(taskRun)); err != nil {
t.Fatalf("Unexpected error when reconciling completed TaskRun : %v", err)
}
newTr, err := clients.Pipeline.TektonV1beta1().TaskRuns(taskRun.Namespace).Get(taskRun.Name, metav1.GetOptions{})
Expand Down Expand Up @@ -1852,7 +1853,7 @@ func TestReconcileOnCancelledTaskRun(t *testing.T) {
c := testAssets.Controller
clients := testAssets.Clients

if err := c.Reconciler.Reconcile(context.Background(), getRunName(taskRun)); err != nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(taskRun)); err != nil {
t.Fatalf("Unexpected error when reconciling completed TaskRun : %v", err)
}
newTr, err := clients.Pipeline.TektonV1beta1().TaskRuns(taskRun.Namespace).Get(taskRun.Name, metav1.GetOptions{})
Expand Down Expand Up @@ -1967,7 +1968,7 @@ func TestReconcileTimeouts(t *testing.T) {
c := testAssets.Controller
clients := testAssets.Clients

if err := c.Reconciler.Reconcile(context.Background(), getRunName(tc.taskRun)); err != nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(tc.taskRun)); err != nil {
t.Fatalf("Unexpected error when reconciling completed TaskRun : %v", err)
}
newTr, err := clients.Pipeline.TektonV1beta1().TaskRuns(tc.taskRun.Namespace).Get(tc.taskRun.Name, metav1.GetOptions{})
Expand Down Expand Up @@ -2224,7 +2225,7 @@ func TestReconcileCloudEvents(t *testing.T) {
t.Fatal(err)
}

if err := c.Reconciler.Reconcile(context.Background(), getRunName(tc.taskRun)); err != nil {
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(tc.taskRun)); err != nil {
t.Errorf("expected no error. Got error %v", err)
}

Expand Down Expand Up @@ -2566,7 +2567,7 @@ func TestReconcileTaskResourceResolutionAndValidation(t *testing.T) {
clients := testAssets.Clients
c := testAssets.Controller

reconcileErr := c.Reconciler.Reconcile(context.Background(), getRunName(tt.d.TaskRuns[0]))
reconcileErr := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(tt.d.TaskRuns[0]))

// When a TaskRun is invalid and can't run, we return a permanent error because
// a regular error will tell the Reconciler to keep trying to reconcile; instead we want to stop
Expand Down
1 change: 1 addition & 0 deletions test/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type Assets struct {
Clients Clients
Informers Informers
Recorder *record.FakeRecorder
Ctx context.Context
}

func AddToInformer(t *testing.T, store cache.Store) func(ktesting.Action) (bool, runtime.Object, error) {
Expand Down