mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-21 16:01:22 +02:00
refactor: modernize code with go fix
This commit is contained in:
@@ -68,8 +68,7 @@ func (r *SubstituteEnvReader) Read(p []byte) (n int, err error) {
|
||||
if nMore > 0 {
|
||||
incomplete = append(incomplete, more[:nMore]...)
|
||||
// Check if pattern is now complete
|
||||
//nolint:modernize
|
||||
if idx := bytes.IndexByte(incomplete, '}'); idx >= 0 {
|
||||
if found := bytes.Contains(incomplete, []byte{'}'}); found {
|
||||
// Pattern complete, append the rest back to chunk
|
||||
chunk = append(chunk, incomplete...)
|
||||
break
|
||||
|
||||
@@ -6,11 +6,6 @@ import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
// Common helper functions
|
||||
func ptr[T any](s T) *T {
|
||||
return &s
|
||||
}
|
||||
|
||||
// Common test function for MustRegisterValidation
|
||||
func TestMustRegisterValidation(t *testing.T) {
|
||||
// Test registering a custom validation
|
||||
|
||||
@@ -63,11 +63,11 @@ func TestValidateWithCustomValidator_PointerMethodWithPointerPassed(t *testing.T
|
||||
input *CustomValidatingInt
|
||||
wantErr bool
|
||||
}{
|
||||
{"valid custom validating int pointer", ptr(CustomValidatingInt(50)), false},
|
||||
{"valid custom validating int pointer", new(CustomValidatingInt(50)), false},
|
||||
{"nil custom validating int pointer", nil, true}, // Should fail because Validate() checks for nil
|
||||
{"invalid custom validating int pointer - zero", ptr(CustomValidatingInt(0)), true},
|
||||
{"invalid custom validating int pointer - negative", ptr(CustomValidatingInt(-5)), true},
|
||||
{"invalid custom validating int pointer - too large", ptr(CustomValidatingInt(200)), true},
|
||||
{"invalid custom validating int pointer - zero", new(CustomValidatingInt(0)), true},
|
||||
{"invalid custom validating int pointer - negative", new(CustomValidatingInt(-5)), true},
|
||||
{"invalid custom validating int pointer - too large", new(CustomValidatingInt(200)), true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -86,10 +86,10 @@ func TestValidateWithCustomValidator_ValueMethodButPointerPassed(t *testing.T) {
|
||||
input *CustomValidatingFloat
|
||||
wantErr bool
|
||||
}{
|
||||
{"valid custom validating float pointer", ptr(CustomValidatingFloat(50.5)), false},
|
||||
{"valid custom validating float pointer", new(CustomValidatingFloat(50.5)), false},
|
||||
{"nil custom validating float pointer", nil, false},
|
||||
{"invalid custom validating float pointer - negative", ptr(CustomValidatingFloat(-5.5)), true},
|
||||
{"invalid custom validating float pointer - too large", ptr(CustomValidatingFloat(2000.5)), true},
|
||||
{"invalid custom validating float pointer - negative", new(CustomValidatingFloat(-5.5)), true},
|
||||
{"invalid custom validating float pointer - too large", new(CustomValidatingFloat(2000.5)), true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -67,10 +67,10 @@ func TestValidateWithCustomValidator_CustomValidatingStringPointer(t *testing.T)
|
||||
input *CustomValidatingString
|
||||
wantErr bool
|
||||
}{
|
||||
{"valid custom validating string pointer", ptr(CustomValidatingString("hello")), false},
|
||||
{"valid custom validating string pointer", new(CustomValidatingString("hello")), false},
|
||||
{"nil custom validating string pointer", nil, true},
|
||||
{"invalid custom validating string pointer - empty", ptr(CustomValidatingString("")), true},
|
||||
{"invalid custom validating string pointer - too short", ptr(CustomValidatingString("a")), true},
|
||||
{"invalid custom validating string pointer - empty", new(CustomValidatingString("")), true},
|
||||
{"invalid custom validating string pointer - too short", new(CustomValidatingString("a")), true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user