Skip to content

Commit 544c078

Browse files
fix test example
1 parent 06052c1 commit 544c078

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

dataloadgen_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ func ExampleLoader() {
3131
panic(err)
3232
}
3333

34-
mappedLoader := dataloadgen.NewLoader(func(ctx context.Context, keys []string) (ret []int, errs []error) {
34+
mappedLoader := dataloadgen.NewMappedLoader(func(ctx context.Context, keys []string) (ret map[string]int, errs map[string]error) {
35+
ret = make(map[string]int, len(keys))
36+
errs = make(map[string]error, len(keys))
3537
for _, key := range keys {
3638
num, err := strconv.ParseInt(key, 10, 32)
37-
ret = append(ret, int(num))
38-
errs = append(errs, err)
39+
ret[key] = int(num)
40+
errs[key] = err
3941
}
4042
return
4143
},
@@ -143,11 +145,11 @@ func TestPanic(t *testing.T) {
143145

144146
func TestMappedLoader(t *testing.T) {
145147
ctx := context.Background()
146-
dl := dataloadgen.NewMappedLoader(func(_ context.Context, keys []string) (map[string]*string, map[string]error) {
148+
dl := dataloadgen.NewMappedLoader(func(_ context.Context, keys []string) (res map[string]*string, errs map[string]error) {
147149
one := "1"
148-
results := map[string]*string{"1": &one}
149-
errs := map[string]error{"3": errors.New("not found error")}
150-
return results, errs
150+
res = map[string]*string{"1": &one}
151+
errs = map[string]error{"3": errors.New("not found error")}
152+
return res, errs
151153
})
152154

153155
thunkOne := dl.LoadThunk(ctx, "1")

0 commit comments

Comments
 (0)