-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmokku_test.go
46 lines (40 loc) · 980 Bytes
/
mokku_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
package mokku_test
import (
"testing"
"github.com/kinbiko/mokku"
)
func TestIntegration(t *testing.T) {
const templateStr = `
type {{.TypeName}}Mock struct { {{ range .Methods }}
{{.Name}}Func func{{.Signature}}{{ end }}
}
{{if .Methods }}{{$typeName := .TypeName}}
{{range $val := .Methods}}func (m *{{$typeName}}Mock) {{$val.Name}}{{$val.Signature}} {
if m.{{$val.Name}}Func == nil {
panic("unexpected call to {{$val.Name}}")
}
{{if $val.HasReturn}}return {{ end }}m.{{$val.Name}}Func{{$val.OrderedParams}}
}
{{ end }}{{ end }}`
got, err := mokku.Mock(mokku.Config{TemplateStr: templateStr}, []byte(`
type Foo interface {
Act()
}`))
if err != nil {
t.Fatalf("unexpected error '%s'", err.Error())
}
exp := `
type FooMock struct {
ActFunc func()
}
func (m *FooMock) Act() {
if m.ActFunc == nil {
panic("unexpected call to Act")
}
m.ActFunc()
}
`
if string(got) != exp {
t.Errorf("unexpected mock created:\n%s\n\nexpected:\n%s", got, exp)
}
}