Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Oct 29, 2024
1 parent cdee2d4 commit 0d92685
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 48 deletions.
41 changes: 3 additions & 38 deletions api/buildstatus/build_status_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -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) {
Expand Down
21 changes: 11 additions & 10 deletions api/buildstatus/models/buildstatus_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"context"
"testing"

v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
Expand All @@ -14,71 +15,71 @@ 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))
})

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))
})
Expand Down

0 comments on commit 0d92685

Please sign in to comment.