From 0d9268590faa07d6af25178d13602a931fd59065 Mon Sep 17 00:00:00 2001 From: Richard87 Date: Tue, 29 Oct 2024 10:43:19 +0100 Subject: [PATCH] fix: tests --- .../build_status_controller_test.go | 41 ++----------------- api/buildstatus/models/buildstatus_test.go | 21 +++++----- 2 files changed, 14 insertions(+), 48 deletions(-) diff --git a/api/buildstatus/build_status_controller_test.go b/api/buildstatus/build_status_controller_test.go index 9cff4cbd..8a2556b4 100644 --- a/api/buildstatus/build_status_controller_test.go +++ b/api/buildstatus/build_status_controller_test.go @@ -125,16 +125,7 @@ func TestGetBuildStatus(t *testing.T) { fakeBuildStatus := mock.NewMockPipelineBadge(ctrl) - var actualCondition v1.RadixJobCondition - var actualPipeline v1.RadixPipelineType - - fakeBuildStatus.EXPECT(). - GetBadge(gomock.Any(), gomock.Any(), gomock.Any()). - DoAndReturn(func(c v1.RadixJobCondition, p v1.RadixPipelineType) ([]byte, error) { - actualCondition = c - actualPipeline = p - return nil, nil - }) + fakeBuildStatus.EXPECT().GetBadge(gomock.Any(), v1.JobRunning, v1.BuildDeploy).Return(nil, nil).Times(1) mockValidator := authnmock.NewMockValidatorInterface(gomock.NewController(t)) mockValidator.EXPECT().ValidateToken(gomock.Any(), gomock.Any()).AnyTimes().Return(controllertest.NewTestPrincipal(true), nil) @@ -144,8 +135,6 @@ func TestGetBuildStatus(t *testing.T) { response := <-responseChannel assert.Equal(t, response.Result().StatusCode, 200) - assert.Equal(t, v1.JobRunning, actualCondition) - assert.Equal(t, v1.BuildDeploy, actualPipeline) }) t.Run("deploy in master - JobRunning", func(t *testing.T) { @@ -154,17 +143,7 @@ func TestGetBuildStatus(t *testing.T) { defer ctrl.Finish() fakeBuildStatus := mock.NewMockPipelineBadge(ctrl) - - var actualCondition v1.RadixJobCondition - var actualPipeline v1.RadixPipelineType - - fakeBuildStatus.EXPECT(). - GetBadge(gomock.Any(), gomock.Any(), gomock.Any()). - DoAndReturn(func(c v1.RadixJobCondition, p v1.RadixPipelineType) ([]byte, error) { - actualCondition = c - actualPipeline = p - return nil, nil - }) + fakeBuildStatus.EXPECT().GetBadge(gomock.Any(), v1.JobSucceeded, v1.Deploy).Return(nil, nil).Times(1) mockValidator := authnmock.NewMockValidatorInterface(gomock.NewController(t)) mockValidator.EXPECT().ValidateToken(gomock.Any(), gomock.Any()).AnyTimes().Return(controllertest.NewTestPrincipal(true), nil) @@ -174,8 +153,6 @@ func TestGetBuildStatus(t *testing.T) { response := <-responseChannel assert.Equal(t, response.Result().StatusCode, 200) - assert.Equal(t, v1.JobSucceeded, actualCondition) - assert.Equal(t, v1.Deploy, actualPipeline) }) t.Run("promote in master - JobFailed", func(t *testing.T) { @@ -184,17 +161,7 @@ func TestGetBuildStatus(t *testing.T) { defer ctrl.Finish() fakeBuildStatus := mock.NewMockPipelineBadge(ctrl) - - var actualCondition v1.RadixJobCondition - var actualPipeline v1.RadixPipelineType - - fakeBuildStatus.EXPECT(). - GetBadge(gomock.Any(), gomock.Any(), gomock.Any()). - DoAndReturn(func(c v1.RadixJobCondition, p v1.RadixPipelineType) ([]byte, error) { - actualCondition = c - actualPipeline = p - return nil, nil - }) + fakeBuildStatus.EXPECT().GetBadge(gomock.Any(), v1.JobFailed, v1.Promote).Return(nil, nil).Times(1) mockValidator := authnmock.NewMockValidatorInterface(gomock.NewController(t)) mockValidator.EXPECT().ValidateToken(gomock.Any(), gomock.Any()).AnyTimes().Return(controllertest.NewTestPrincipal(true), nil) @@ -204,8 +171,6 @@ func TestGetBuildStatus(t *testing.T) { response := <-responseChannel assert.Equal(t, response.Result().StatusCode, 200) - assert.Equal(t, v1.JobFailed, actualCondition) - assert.Equal(t, v1.Promote, actualPipeline) }) t.Run("return status 500", func(t *testing.T) { diff --git a/api/buildstatus/models/buildstatus_test.go b/api/buildstatus/models/buildstatus_test.go index fc913d1f..e6200b23 100644 --- a/api/buildstatus/models/buildstatus_test.go +++ b/api/buildstatus/models/buildstatus_test.go @@ -1,6 +1,7 @@ package models import ( + "context" "testing" v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1" @@ -14,42 +15,42 @@ func Test_PipelineBadgeBuilder(t *testing.T) { t.Run("failed condition", func(t *testing.T) { t.Parallel() expected := "-Failing" - actual, err := badgeBuilder.GetBadge(v1.JobFailed, v1.RadixPipelineType("")) + actual, err := badgeBuilder.GetBadge(context.Background(), v1.JobFailed, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("queued condition", func(t *testing.T) { t.Parallel() expected := "-Pending" - actual, err := badgeBuilder.GetBadge(v1.JobQueued, v1.RadixPipelineType("")) + actual, err := badgeBuilder.GetBadge(context.Background(), v1.JobQueued, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("running condition", func(t *testing.T) { t.Parallel() expected := "-Running" - actual, err := badgeBuilder.GetBadge(v1.JobRunning, v1.RadixPipelineType("")) + actual, err := badgeBuilder.GetBadge(context.Background(), v1.JobRunning, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("stopped condition", func(t *testing.T) { t.Parallel() expected := "-Stopped" - actual, err := badgeBuilder.GetBadge(v1.JobStopped, v1.RadixPipelineType("")) + actual, err := badgeBuilder.GetBadge(context.Background(), v1.JobStopped, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("succeeded condition", func(t *testing.T) { t.Parallel() expected := "-Succeeded" - actual, err := badgeBuilder.GetBadge(v1.JobSucceeded, v1.RadixPipelineType("")) + actual, err := badgeBuilder.GetBadge(context.Background(), v1.JobSucceeded, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("waiting condition", func(t *testing.T) { t.Parallel() expected := "-Pending" - actual, err := badgeBuilder.GetBadge(v1.JobWaiting, v1.RadixPipelineType("")) + actual, err := badgeBuilder.GetBadge(context.Background(), v1.JobWaiting, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) @@ -57,28 +58,28 @@ func Test_PipelineBadgeBuilder(t *testing.T) { t.Run("build-deploy type", func(t *testing.T) { t.Parallel() expected := "build-deploy-Succeeded" - actual, err := badgeBuilder.GetBadge(v1.JobSucceeded, v1.BuildDeploy) + actual, err := badgeBuilder.GetBadge(context.Background(), v1.JobSucceeded, v1.BuildDeploy) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("promote type", func(t *testing.T) { t.Parallel() expected := "promote-Succeeded" - actual, err := badgeBuilder.GetBadge(v1.JobSucceeded, v1.Promote) + actual, err := badgeBuilder.GetBadge(context.Background(), v1.JobSucceeded, v1.Promote) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("deploy type", func(t *testing.T) { t.Parallel() expected := "deploy-Succeeded" - actual, err := badgeBuilder.GetBadge(v1.JobSucceeded, v1.Deploy) + actual, err := badgeBuilder.GetBadge(context.Background(), v1.JobSucceeded, v1.Deploy) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("unhandled type", func(t *testing.T) { t.Parallel() expected := "-Succeeded" - actual, err := badgeBuilder.GetBadge(v1.JobSucceeded, v1.RadixPipelineType("unhandled")) + actual, err := badgeBuilder.GetBadge(context.Background(), v1.JobSucceeded, v1.RadixPipelineType("unhandled")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) })