Skip to content

Commit

Permalink
Add unit test for isComponentLinked
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <[email protected]>
  • Loading branch information
mmorhun committed Oct 19, 2023
1 parent 4889322 commit a5677e8
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions controllers/imagerepository_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,61 @@ func TestGetRemoteSecretName(t *testing.T) {
})
}
}

func TestIsComponentLinked(t *testing.T) {
testCases := []struct {
name string
imageRepository *imagerepositoryv1alpha1.ImageRepository
expect bool
}{
{
name: "Should recognize linked component",
imageRepository: &imagerepositoryv1alpha1.ImageRepository{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
ApplicationNameLabelName: "application-name",
ComponentNameLabelName: "component-name",
},
},
},
expect: true,
},
{
name: "Should not be linked to component if labels missing",
imageRepository: &imagerepositoryv1alpha1.ImageRepository{},
expect: false,
},
{
name: "Should not be linked to component if application label missing",
imageRepository: &imagerepositoryv1alpha1.ImageRepository{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
ComponentNameLabelName: "component-name",
},
},
},
expect: false,
},
{
name: "Should not be linked to component if component label missing",
imageRepository: &imagerepositoryv1alpha1.ImageRepository{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
ApplicationNameLabelName: "application-name",
},
},
},
expect: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := isComponentLinked(tc.imageRepository)

if got != tc.expect {
t.Errorf("isComponentLinked() for %v: expected %t but got %t", tc.imageRepository, tc.expect, got)
}
})
}
}

0 comments on commit a5677e8

Please sign in to comment.