From ea5cc07bf2e032ed342e7f6aaeb108503a0011a0 Mon Sep 17 00:00:00 2001 From: Nader Ziada Date: Tue, 21 May 2019 12:46:39 -0400 Subject: [PATCH] fix linting issues --- pkg/apis/pipeline/v1alpha1/task_defaults.go | 1 - .../taskrun/resources/image_exporter_test.go | 35 ++++++++++++++++--- .../v1alpha1/taskrun/taskrun_test.go | 5 ++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/pkg/apis/pipeline/v1alpha1/task_defaults.go b/pkg/apis/pipeline/v1alpha1/task_defaults.go index da56e47ba59..36385647a43 100644 --- a/pkg/apis/pipeline/v1alpha1/task_defaults.go +++ b/pkg/apis/pipeline/v1alpha1/task_defaults.go @@ -36,5 +36,4 @@ func (ts *TaskSpec) SetDefaults(ctx context.Context) { } } } - return } diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/image_exporter_test.go b/pkg/reconciler/v1alpha1/taskrun/resources/image_exporter_test.go index eac34f9f80f..bb301abb1d7 100644 --- a/pkg/reconciler/v1alpha1/taskrun/resources/image_exporter_test.go +++ b/pkg/reconciler/v1alpha1/taskrun/resources/image_exporter_test.go @@ -200,7 +200,7 @@ func TestAddOutputImageDigestExporter(t *testing.T) { } } -func TestUpdateTaskRunStatus(t *testing.T) { +func TestUpdateTaskRunStatus_withValidJson(t *testing.T) { for _, c := range []struct { desc string podLog []byte @@ -237,7 +237,31 @@ func TestUpdateTaskRunStatus(t *testing.T) { Name: "source-image", Digest: "sha256:1234", }}, - }, { + }} { + t.Run(c.desc, func(t *testing.T) { + names.TestingSeed() + c.taskRun.Status.SetCondition(&apis.Condition{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionTrue, + }) + err := UpdateTaskRunStatusWithResourceResult(c.taskRun, c.podLog) + if err != nil { + t.Errorf("UpdateTaskRunStatusWithResourceResult failed with error: %s", err) + } + if d := cmp.Diff(c.taskRun.Status.ResourcesResult, c.want); d != "" { + t.Errorf("post build steps mismatch: %s", d) + } + }) + } +} + +func TestUpdateTaskRunStatus_withInvalidJson(t *testing.T) { + for _, c := range []struct { + desc string + podLog []byte + taskRun *v1alpha1.TaskRun + want []v1alpha1.PipelineResourceResult + }{{ desc: "image resource exporter with malformed json output", podLog: []byte("extralogscamehere[{\"name\":\"source-image\",\"digest\":\"sha256:1234\"}]"), taskRun: &v1alpha1.TaskRun{ @@ -282,9 +306,12 @@ func TestUpdateTaskRunStatus(t *testing.T) { Type: apis.ConditionSucceeded, Status: corev1.ConditionTrue, }) - UpdateTaskRunStatusWithResourceResult(c.taskRun, c.podLog) + err := UpdateTaskRunStatusWithResourceResult(c.taskRun, c.podLog) + if err == nil { + t.Error("UpdateTaskRunStatusWithResourceResult expected to fail with error") + } if d := cmp.Diff(c.taskRun.Status.ResourcesResult, c.want); d != "" { - t.Fatalf("post build steps mismatch: %s", d) + t.Errorf("post build steps mismatch: %s", d) } }) } diff --git a/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go b/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go index b8cac12e548..03bcf8bc05d 100644 --- a/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go +++ b/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go @@ -1759,7 +1759,10 @@ func TestUpdateStatusFromPod(t *testing.T) { }} for _, r := range rs { - pipelineResourceInformer.Informer().GetIndexer().Add(r) + err := pipelineResourceInformer.Informer().GetIndexer().Add(r) + if err != nil { + t.Errorf("pipelineResourceInformer.Informer().GetIndexer().Add(r) failed with err: %s", err) + } } now := metav1.Now()