-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_test.go
54 lines (37 loc) · 1.08 KB
/
mock_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
package mockinator
import (
. "github.com/franela/goblin"
"github.com/pkg/errors"
"testing"
)
const expectedIntReturn = 1
var expectedError = errors.New("teste")
type mockExemple struct {
Mock Mockinator
}
func (d *mockExemple) functionExample() (int, error) {
a, b := d.Mock.Execute(d.functionExample)
return a.(int), b
}
func (d *mockExemple) functionOnlyError() error {
return d.Mock.ExecuteAndReturnErrorOnly(d.functionOnlyError)
}
func TestMock(t *testing.T) {
mock := Mockinator{}
mock.MustInit()
d := mockExemple{Mock: mock}
g := Goblin(t)
g.Describe("should mockinator work as expected", func() {
g.It("should mock return as expected", func() {
d.Mock.SetError(d.functionExample, expectedError)
d.Mock.SetReturn(d.functionExample, expectedIntReturn)
number, err := d.functionExample()
g.Assert(number).Equal(expectedIntReturn)
g.Assert(err).Equal(expectedError)
})
g.It("should mock return only error as expected", func() {
d.Mock.SetError(d.functionOnlyError, expectedError)
g.Assert(d.functionOnlyError()).Equal(expectedError)
})
})
}