-
Notifications
You must be signed in to change notification settings - Fork 2
/
generic_go1.18_test.go
61 lines (42 loc) · 1.13 KB
/
generic_go1.18_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
49
50
51
52
53
54
55
56
57
58
59
60
61
//go:build go1.18
// +build go1.18
package usecase_test
import (
"context"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/swaggest/usecase"
)
func TestNewIOI_classic(t *testing.T) {
u := usecase.NewIOI(0, new(string), func(ctx context.Context, input, output interface{}) error {
in, ok := input.(int)
assert.True(t, ok)
out, ok := output.(*string)
assert.True(t, ok)
*out = strconv.Itoa(in)
return nil
})
ctx := context.Background()
var out string
assert.NoError(t, u.Interact(ctx, 123, &out))
assert.Equal(t, "123", out)
}
func TestNewInteractor(t *testing.T) {
u := usecase.NewInteractor(func(ctx context.Context, input int, output *string) error {
*output = strconv.Itoa(input)
return nil
}, func(i *usecase.IOInteractor) {
i.SetTags("foo")
})
u.SetDescription("Foo.")
ctx := context.Background()
var out string
assert.NoError(t, u.Interact(ctx, 123, &out))
assert.Equal(t, "123", out)
out = ""
assert.NoError(t, u.Invoke(ctx, 123, &out))
assert.Equal(t, "123", out)
assert.Equal(t, "invalid type", usecase.ErrInvalidType.Error())
assert.Equal(t, []string{"foo"}, u.Tags())
}