test: clean up reward-hacking backend tests (#5563)

This commit is contained in:
Seefs
2026-06-17 16:47:52 +08:00
committed by GitHub
parent b798e3496f
commit 8d87d5fd8b
11 changed files with 56 additions and 485 deletions
+2 -15
View File
@@ -1,6 +1,7 @@
package common
import (
"strings"
"testing"
"github.com/QuantumNous/new-api/constant"
@@ -107,7 +108,7 @@ func TestValidateRedirectURL(t *testing.T) {
t.Errorf("ValidateRedirectURL(%q) expected error containing %q, got nil", tt.url, tt.errContains)
return
}
if tt.errContains != "" && !contains(err.Error(), tt.errContains) {
if tt.errContains != "" && !strings.Contains(err.Error(), tt.errContains) {
t.Errorf("ValidateRedirectURL(%q) error = %q, want error containing %q", tt.url, err.Error(), tt.errContains)
}
} else {
@@ -118,17 +119,3 @@ func TestValidateRedirectURL(t *testing.T) {
})
}
}
func contains(s, substr string) bool {
return len(s) >= len(substr) && (s == substr || len(substr) == 0 ||
(len(s) > 0 && len(substr) > 0 && findSubstring(s, substr)))
}
func findSubstring(s, substr string) bool {
for i := 0; i <= len(s)-len(substr); i++ {
if s[i:i+len(substr)] == substr {
return true
}
}
return false
}