28 lines
568 B
Go
28 lines
568 B
Go
package patterns
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestFunctionalOptions(t *testing.T) {
|
|
c := NewClient(WithTimeout(2*time.Second), WithRetries(5))
|
|
if c.Timeout != 2*time.Second || c.Retries != 5 {
|
|
t.Fatalf("unexpected client: %+v", c)
|
|
}
|
|
}
|
|
|
|
func TestWorkerPool(t *testing.T) {
|
|
results := RunWorkerPool(3, []int{1, 2, 3, 4, 5}, func(x int) int { return x * 10 })
|
|
if len(results) != 5 {
|
|
t.Fatalf("expected 5 results, got %d", len(results))
|
|
}
|
|
sum := 0
|
|
for _, r := range results {
|
|
sum += r
|
|
}
|
|
if sum != 150 {
|
|
t.Fatalf("got sum %d, want 150", sum)
|
|
}
|
|
}
|