-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmethod_invoker_test.go
92 lines (77 loc) · 3 KB
/
method_invoker_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package aqua
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
type invokerMock struct{}
func (me *invokerMock) InputZero() {}
func (me *invokerMock) InputInt(a int) {}
func (me *invokerMock) InputMulti(a int, b *string, c iInvoker, d invokerMock, e *invokerMock) {}
func (me *invokerMock) OutputZero() {}
func (me *invokerMock) OutputInt() int {
return 0
}
func (me *invokerMock) OutputMulti() (int, *string, iInvoker, invokerMock, *invokerMock) {
s := "string"
return 0, &s, invokerMock{}, invokerMock{}, &invokerMock{}
}
type iInvoker interface{}
func TestInvokerCtor(t *testing.T) {
Convey("Given that Invocker::ctor expects address of struct", t, func() {
Convey("Then it should throw panic on being passed a literal", func() {
So(func() { NewMethodInvoker("abc", "any") }, ShouldPanic)
})
Convey("Then it should throw panic on being passed a struct", func() {
So(func() { NewMethodInvoker(invokerMock{}, "any") }, ShouldPanic)
})
Convey("Then it should accept struct address safely", func() {
So(func() { NewMethodInvoker(&invokerMock{}, "InputZero") }, ShouldNotPanic)
})
})
}
func TestInputParameters(t *testing.T) {
a := &invokerMock{}
Convey("The Invoker", t, func() {
Convey("Should correctly identify no/zero inpParamsuts", func() {
i := NewMethodInvoker(a, "InputZero")
So(i.inpCount, ShouldEqual, 0)
})
Convey("Should correctly identify int inpParamsuts", func() {
i := NewMethodInvoker(a, "InputInt")
So(i.inpCount, ShouldEqual, 1)
So(i.inpParams[0], ShouldEqual, "int")
})
Convey("Should correctly identify multi inpParamsut parameters", func() {
i := NewMethodInvoker(a, "InputMulti")
So(i.inpCount, ShouldEqual, 5)
So(i.inpParams[0], ShouldEqual, "int")
So(i.inpParams[1], ShouldEqual, "*string")
So(i.inpParams[2], ShouldEqual, "i:github.com/tolexo/aqua.iInvoker")
So(i.inpParams[3], ShouldEqual, "st:github.com/tolexo/aqua.invokerMock")
So(i.inpParams[4], ShouldEqual, "*st:github.com/tolexo/aqua.invokerMock")
})
})
}
func TestOutputParameters(t *testing.T) {
a := &invokerMock{}
Convey("The Invoker", t, func() {
Convey("Should correctly identify no/zero outParamsput", func() {
i := NewMethodInvoker(a, "OutputZero")
So(i.outCount, ShouldEqual, 0)
})
Convey("Should correctly identify int outParamsput", func() {
i := NewMethodInvoker(a, "OutputInt")
So(i.outCount, ShouldEqual, 1)
So(i.outParams[0], ShouldEqual, "int")
})
Convey("Should correctly identify multi outParamsput parameters", func() {
i := NewMethodInvoker(a, "OutputMulti")
So(i.outCount, ShouldEqual, 5)
So(i.outParams[0], ShouldEqual, "int")
So(i.outParams[1], ShouldEqual, "*string")
So(i.outParams[2], ShouldEqual, "i:github.com/tolexo/aqua.iInvoker")
So(i.outParams[3], ShouldEqual, "st:github.com/tolexo/aqua.invokerMock")
So(i.outParams[4], ShouldEqual, "*st:github.com/tolexo/aqua.invokerMock")
})
})
}