Skip to content

Commit

Permalink
Adding unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
satr committed Jul 25, 2023
1 parent 650c261 commit f753485
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/apis/batch/kubejob_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package batch

import (
"testing"

radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
)

func Test_getJobImage(t *testing.T) {
type args struct {
jobComponentImage string
imageTagName string
}
tests := []struct {
name string
args args
want string
}{
{name: "image without repo and tag, no imageTagName", args: args{jobComponentImage: "alpine", imageTagName: ""}, want: "alpine"},
{name: "image with repo, no tag, no imageTagName", args: args{jobComponentImage: "somerepo/alpine", imageTagName: ""}, want: "somerepo/alpine"},
{name: "image with repo, org, no tag, no imageTagName", args: args{jobComponentImage: "somerepo/org/alpine", imageTagName: ""}, want: "somerepo/org/alpine"},
{name: "image with repo and domain, org, no tag, no imageTagName", args: args{jobComponentImage: "somerepo.com/org/alpine", imageTagName: ""}, want: "somerepo/org/alpine"},
{name: "image without repo and tag, no imageTagName", args: args{jobComponentImage: "alpine", imageTagName: ""}, want: "alpine"},
{name: "image with repo and tag, no imageTagName", args: args{jobComponentImage: "somerepo/alpine", imageTagName: ""}, want: "somerepo/alpine"},
{name: "image with repo, org and tag, no imageTagName", args: args{jobComponentImage: "somerepo/org/alpine", imageTagName: ""}, want: "somerepo/org/alpine"},
{name: "image with repo and domain, org and tag, no imageTagName", args: args{jobComponentImage: "somerepo.com/org/alpine", imageTagName: ""}, want: "somerepo/org/alpine"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
jobComponent := radixv1.RadixDeployJobComponent{Image: tt.args.jobComponentImage}
radixBatch := radixv1.RadixBatchJob{ImageTagName: tt.args.imageTagName}
if gotImage := getJobImage(&jobComponent, &radixBatch); gotImage != tt.want {
t.Errorf("getJobImage() = %v, want %v", gotImage, tt.want)
}
})
}
}

0 comments on commit f753485

Please sign in to comment.