-
Notifications
You must be signed in to change notification settings - Fork 411
/
router_test.go
44 lines (33 loc) · 1.22 KB
/
router_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
package erpc
import (
"reflect"
"testing"
"github.com/andeya/goutil"
"github.com/stretchr/testify/assert"
)
type A struct {
B
}
func (A) X0() {}
func (*A) X1() {}
type B struct {
}
func (B) Y0() {}
func (*B) Y1() {}
func TestIsCompositionMethod(t *testing.T) {
assert.False(t, goutil.IsCompositionMethod(reflect.TypeOf(A{}).Method(0)))
assert.True(t, goutil.IsCompositionMethod(reflect.TypeOf(A{}).Method(1)))
assert.False(t, goutil.IsCompositionMethod(reflect.TypeOf(&A{}).Method(0)), reflect.TypeOf(&A{}).Method(0))
assert.False(t, goutil.IsCompositionMethod(reflect.TypeOf(&A{}).Method(1)))
assert.True(t, goutil.IsCompositionMethod(reflect.TypeOf(&A{}).Method(2)))
assert.True(t, goutil.IsCompositionMethod(reflect.TypeOf(&A{}).Method(3)))
assert.False(t, goutil.IsCompositionMethod(reflect.TypeOf(B{}).Method(0)))
assert.False(t, goutil.IsCompositionMethod(reflect.TypeOf(&B{}).Method(0)))
assert.False(t, goutil.IsCompositionMethod(reflect.TypeOf(&B{}).Method(1)))
}
func TestResolveCtrlStructOrPoolFunc(t *testing.T) {
builder, err := resolveCtrlStructOrPoolFunc(func() CtrlStructPtr { return new(A) })
assert.NoError(t, err)
assert.NotNil(t, builder)
assert.Equal(t, reflect.TypeOf(&A{}), builder().Type())
}