优化结构
This commit is contained in:
@@ -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{}{}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user