refactor: modernize code with go fix

This commit is contained in:
yusing
2026-02-21 13:03:21 +08:00
parent 64ffe44a2d
commit 3a7d1f8b18
12 changed files with 32 additions and 61 deletions

View File

@@ -27,9 +27,9 @@ func TestValidateWithCustomValidator_StringPointer(t *testing.T) {
input *string
wantErr bool
}{
{"valid string pointer", ptr("hello"), false},
{"valid string pointer", new("hello"), false},
{"nil string pointer", nil, false},
{"empty string pointer", ptr(""), false},
{"empty string pointer", new(""), false},
}
for _, tt := range tests {
@@ -69,11 +69,11 @@ func TestValidateWithCustomValidator_CustomValidatingPointerStringPointer(t *tes
input *CustomValidatingPointerString
wantErr bool
}{
{"valid custom validating pointer string", customStringPointerPtr(CustomValidatingPointerString("hello")), false},
{"valid custom validating pointer string", new(CustomValidatingPointerString("hello")), false},
{"nil custom validating pointer string", nil, true}, // Should fail because Validate() checks for nil
{"invalid custom validating pointer string - empty", customStringPointerPtr(CustomValidatingPointerString("")), true},
{"invalid custom validating pointer string - too short", customStringPointerPtr(CustomValidatingPointerString("a")), true},
{"valid custom validating pointer string - minimum length", customStringPointerPtr(CustomValidatingPointerString("ab")), false},
{"invalid custom validating pointer string - empty", new(CustomValidatingPointerString("")), true},
{"invalid custom validating pointer string - too short", new(CustomValidatingPointerString("a")), true},
{"valid custom validating pointer string - minimum length", new(CustomValidatingPointerString("ab")), false},
}
for _, tt := range tests {
@@ -85,8 +85,3 @@ func TestValidateWithCustomValidator_CustomValidatingPointerStringPointer(t *tes
})
}
}
// Helper function to create CustomValidatingPointerString pointer
func customStringPointerPtr(s CustomValidatingPointerString) *CustomValidatingPointerString {
return &s
}