-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmockgen_test.go
55 lines (46 loc) · 1.7 KB
/
mockgen_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
package main
import (
"io/ioutil"
"os"
"testing"
"github.com/otiai10/copy"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFindInterface(t *testing.T) {
iface, err := findInterface("./test/inputnew/example/types.go", "Exampler")
require.NoError(t, err)
methods := iface.Methods()
assert.Equal(t, 3, len(methods))
assert.Equal(t, "FunctionA", methods[0].Name)
assert.Equal(t, "FunctionC", methods[1].Name)
assert.Equal(t, "FunctionZ", methods[2].Name)
}
func TestGenerateNewMock(t *testing.T) {
cleanup(t)
err := generateNewMock("./test/inputnew/example/types.go", "Exampler", "TestMock")
require.NoError(t, err)
expected, err := ioutil.ReadFile("./test/expectednew/result.go")
require.NoError(t, err, "error in test setup")
actual, err := ioutil.ReadFile("./test/inputnew/example/examplemock/testmock.go")
require.NoError(t, err)
assert.Equal(t, string(expected), string(actual))
}
func TestUpdateMock(t *testing.T) {
cleanup(t)
err := copy.Copy("./test/inputfix/existing", "./test/inputfix/example/examplemock")
require.NoError(t, err, "error in test setup")
err = updateMock("./test/inputfix/example/types.go", "Exampler")
require.NoError(t, err)
expected, err := ioutil.ReadFile("./test/expectedfix/result.go")
require.NoError(t, err, "error in test setup")
actual, err := ioutil.ReadFile("./test/inputfix/example/examplemock/testmock.go")
require.NoError(t, err)
assert.Equal(t, string(expected), string(actual))
}
func cleanup(t *testing.T) {
err := os.RemoveAll("./test/inputnew/example/examplemock")
assert.NoError(t, err, "error in test setup")
err = os.RemoveAll("./test/inputfix/example/examplemock")
assert.NoError(t, err, "error in test setup")
}