forked from fgrosse/goldi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
x_testsuite_test.go
105 lines (80 loc) · 2.06 KB
/
x_testsuite_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
93
94
95
96
97
98
99
100
101
102
103
104
105
package goldi_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strings"
"testing"
)
func TestFactories(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Goldi Test Suite")
}
// The types below act as mocks in the tests
// NewFoo returns a new instance of Foo
func NewFoo() *Foo {
return &Foo{}
}
// Foo is an example type that is used in the tests only
type Foo struct {
Value, AnotherParameter string
}
// ReturnString returns Foo.Value
func (f *Foo) ReturnString(suffix string) string {
return f.Value + " " + suffix
}
type Bar struct{}
type Baz struct {
Parameter1, Parameter2 string
}
func NewBar() *Bar {
return &Bar{}
}
type MockType struct {
StringParameter string
BoolParameter bool
}
func (t *MockType) DoStuff() string {
return "I did stuff"
}
func (t *MockType) ReturnString(suffix string) string {
return t.StringParameter + " " + suffix
}
func NewMockType() *MockType {
return &MockType{}
}
func NewMockTypeWithArgs(stringParameter string, boolParameter bool) *MockType {
return &MockType{stringParameter, boolParameter}
}
func NewVariadicMockType(foo bool, bar string, parameters ...string) *MockType {
return &MockType{
BoolParameter: foo,
StringParameter: strings.Join(parameters, ", "),
}
}
type someFunc func(string) string
func NewMockTypeFromStringFunc(s string, sf someFunc) *MockType {
return &MockType{StringParameter: sf(s)}
}
func NewVariadicMockTypeFuncs(funcs ...someFunc) *MockType {
m := &MockType{}
for _, f := range funcs {
m.StringParameter = f(m.StringParameter)
}
return m
}
type MockTypeFactory struct {
HasBeenUsed bool
}
func (g *MockTypeFactory) NewMockType() *MockType {
g.HasBeenUsed = true
return &MockType{}
}
type TypeForServiceInjection struct {
InjectedType *MockType
}
func NewTypeForServiceInjection(injectedType *MockType) *TypeForServiceInjection {
return &TypeForServiceInjection{injectedType}
}
func NewTypeForServiceInjectionWithArgs(injectedType *MockType, name, location string, flag bool) *TypeForServiceInjection {
return &TypeForServiceInjection{injectedType}
}