-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go_test.go
40 lines (30 loc) · 900 Bytes
/
go_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
package fun_test
import (
"context"
"testing"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/tozd/go/errors"
"gitlab.com/tozd/go/fun"
)
func TestGo(t *testing.T) {
t.Parallel()
f := fun.Go[string, string]{
Fun: func(_ context.Context, input ...string) (string, errors.E) {
return input[0] + input[0], nil
},
}
ctx := zerolog.New(zerolog.NewTestWriter(t)).WithContext(context.Background())
errE := f.Init(ctx)
require.NoError(t, errE, "% -+#.1v", errE)
output, errE := f.Call(ctx, "foo")
require.NoError(t, errE, "% -+#.1v", errE)
assert.Equal(t, "foofoo", output)
output, errE = f.Variadic()(ctx, "foo")
require.NoError(t, errE, "% -+#.1v", errE)
assert.Equal(t, "foofoo", output)
output, errE = f.Unary()(ctx, "foo")
require.NoError(t, errE, "% -+#.1v", errE)
assert.Equal(t, "foofoo", output)
}