-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers_test.go
More file actions
43 lines (35 loc) · 881 Bytes
/
helpers_test.go
File metadata and controls
43 lines (35 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package batchify
import (
"os"
"testing"
"time"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
)
// https://github.com/stretchr/testify/issues/1101
func testWithTimeout(t *testing.T, timeout time.Duration) { //nolint:unused
t.Helper()
testFinished := make(chan struct{})
t.Cleanup(func() { close(testFinished) })
go func() {
select {
case <-testFinished:
case <-time.After(timeout):
t.Errorf("test timed out after %s", timeout)
os.Exit(1)
}
}()
}
func mockDoOk(keys []string) (map[string]string, error) {
return lo.SliceToMap(keys, func(key string) (string, string) {
return key, key + key
}), nil
}
func mockDoKo(keys []string) (map[string]string, error) {
return lo.SliceToMap(keys, func(key string) (string, string) {
return key, key + key
}), assert.AnError
}
func mockHasher(key string) uint64 {
return uint64(len(key))
}