Skip to content

Commit e81adde

Browse files
committed
use assert to validate annotation key
1 parent 78a982d commit e81adde

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

pkg/controller/perconaservermongodb/custom_users_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -478,22 +478,15 @@ func TestBuildAnnotationKey(t *testing.T) {
478478

479479
// Extract the name part (after "percona.com/")
480480
prefix := "percona.com/"
481-
if !strings.HasPrefix(got, prefix) {
482-
t.Errorf("buildAnnotationKey() = %v, should start with %v", got, prefix)
483-
}
481+
assert.True(t, strings.HasPrefix(got, prefix), "buildAnnotationKey() = %v, should start with %v", got, prefix)
484482

483+
// Verify the annotation key name part is within Kubernetes limit
485484
namePart := got[len(prefix):]
486485
gotLen := len(got)
487-
488-
// Verify the annotation key name part is within Kubernetes limit
489-
if len(namePart) > tt.maxLength {
490-
t.Errorf("buildAnnotationKey() name part length = %v, should be <= %v. Got: %v", len(namePart), tt.maxLength, got)
491-
}
486+
assert.True(t, len(namePart) <= tt.maxLength, "buildAnnotationKey() name part length = %v, should be <= %v. Got: %v", len(namePart), tt.maxLength, got)
492487

493488
// Verify it ends with "-hash"
494-
if !strings.HasSuffix(got, "-hash") {
495-
t.Errorf("buildAnnotationKey() = %v, should end with '-hash'", got)
496-
}
489+
assert.True(t, strings.HasSuffix(got, "-hash"), "buildAnnotationKey() = %v, should end with '-hash'", got)
497490

498491
// Verify exact match for non-truncated cases
499492
if gotLen <= tt.maxLength && tt.want != "" {

0 commit comments

Comments
 (0)