优化结构

This commit is contained in:
Yvan
2026-08-22 22:34:33 +08:00
parent 0126995090
commit b18baf1547
26 changed files with 501 additions and 80 deletions
@@ -18,3 +18,40 @@ func TestEverySupportedProviderHasAdapter(t *testing.T) {
})
}
}
func TestNewNormalizesProviderIdentifier(t *testing.T) {
for _, provider := range bizpayment.SupportedPaymentProviders {
adapter, err := New(" " + provider + " ")
if err != nil {
t.Fatalf("New(%q): %v", provider, err)
}
if adapter == nil {
t.Fatalf("New(%q) returned nil", provider)
}
}
}
func TestNewRejectsUnknownProvider(t *testing.T) {
if _, err := New("unknown-provider"); err == nil {
t.Fatal("unknown provider unexpectedly accepted")
}
}
func TestNonceIsUniqueForConcurrentRequests(t *testing.T) {
const count = 1000
values := make(chan string, count)
for i := 0; i < count; i++ {
go func() { values <- nonce() }()
}
seen := make(map[string]struct{}, count)
for i := 0; i < count; i++ {
value := <-values
if value == "" {
t.Fatal("nonce returned an empty value")
}
if _, exists := seen[value]; exists {
t.Fatalf("nonce collision for %q", value)
}
seen[value] = struct{}{}
}
}