-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoption_test.go
48 lines (37 loc) · 2.11 KB
/
option_test.go
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
44
45
46
47
48
package dataloader
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"context"
"reflect"
)
var _ = Describe("Option", func() {
It("can disable batch", func() {
dl := New[string, string, string](context.TODO(), func(ctx context.Context, keys []string) []Result[string] { return []Result[string]{} }, WithBatch[string, string, string](false))
Expect(dl.(*loader[string, string, string]).maxBatchSize).To(Equal(1))
})
It("can set max batch size", func() {
dl := New[string, string, string](context.TODO(), func(ctx context.Context, keys []string) []Result[string] { return []Result[string]{} }, WithMaxBatchSize[string, string, string](10))
Expect(dl.(*loader[string, string, string]).maxBatchSize).To(Equal(10))
})
It("can set schedule function", func() {
scheduleFn := (func(ctx context.Context, _ Batch, callback func()) { callback() })
dl := New[string, string, string](context.TODO(), func(ctx context.Context, keys []string) []Result[string] { return []Result[string]{} }, WithBatchScheduleFn[string, string, string](scheduleFn))
pointer1 := reflect.ValueOf(dl.(*loader[string, string, string]).batchScheduleFn).Pointer()
pointer2 := reflect.ValueOf(scheduleFn).Pointer()
Expect(pointer1).To(Equal(pointer2))
})
It("can set cache key function", func() {
cacheKeyFn := func(ctx context.Context, key string) (string, error) { return "", nil }
dl := New[string, string, string](context.TODO(), func(ctx context.Context, keys []string) []Result[string] { return []Result[string]{} }, WithCacheKeyFn[string, string, string](cacheKeyFn))
pointer1 := reflect.ValueOf(dl.(*loader[string, string, string]).cacheKeyFn).Pointer()
pointer2 := reflect.ValueOf(cacheKeyFn).Pointer()
Expect(pointer1).To(Equal(pointer2))
})
It("can set cache map", func() {
cacheMap := NewNoCache[string, *Thunk[string]]()
dl := New[string, string, string](context.TODO(), func(ctx context.Context, keys []string) []Result[string] { return []Result[string]{} }, WithCacheMap[string, string, string](cacheMap))
acutal := <-dl.(*loader[string, string, string]).cacheMap
Expect(acutal).To(Equal(cacheMap))
})
})