-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_test.go
137 lines (111 loc) · 2.83 KB
/
common_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package databuilder
import (
"context"
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
type TestStruct1 struct {
Value string
}
type TestStruct2 struct {
Value string
}
type TestStruct3 struct {
Value string
}
type TestStruct4 struct {
Value string
}
type TestStruct5 struct {
Value string
}
type TestInter interface {
}
func DBTestFunc(_ context.Context, s TestStruct1) (TestStruct2, error) {
fmt.Println("CALLED DBTestFunc")
return TestStruct2{
Value: strings.ReplaceAll(s.Value, "-", "_"),
}, nil
}
func DBTestFunc2(_ context.Context) (TestStruct1, error) {
fmt.Println("CALLED DBTestFunc2")
return TestStruct1{
Value: "ABCD",
}, nil
}
func DBTestFunc3(_ context.Context, s TestStruct2) (TestStruct1, error) {
fmt.Println("CALLED DBTestFunc3")
return TestStruct1{
Value: s.Value,
}, nil
}
func DBTestFunc4(_ context.Context, s TestStruct1) (TestStruct3, error) {
fmt.Println("CALLED DBTestFunc4")
return TestStruct3{
Value: s.Value,
}, nil
}
func DBTestFunc5(_ context.Context, s TestStruct1) (TestStruct2, error) {
fmt.Println("CALLED DBTestFunc5")
return TestStruct2{
Value: strings.ReplaceAll(s.Value, "-", "--"),
}, nil
}
func DBTestFunc6(_ context.Context, s TestStruct1) (TestStruct3, error) {
fmt.Println("CALLED DBTestFunc6")
return TestStruct3{
Value: s.Value,
}, nil
}
func DBTestFunc7(_ context.Context, s TestStruct3) (TestStruct4, error) {
fmt.Println("CALLED DBTestFunc7")
return TestStruct4{
Value: s.Value,
}, nil
}
func DBTestFuncErr(_ context.Context, s TestStruct1) (TestStruct2, error) {
fmt.Println("CALLED DBTestFuncErr")
return TestStruct2{
Value: s.Value,
}, fmt.Errorf("DBTestFunc encountered an error")
}
func DBTestFuncAfterErr(_ context.Context, s TestStruct2) (TestStruct5, error) {
fmt.Println("CALLED DBTestFuncAfterErr")
return TestStruct5{
Value: s.Value,
}, nil
}
func DBTestFuncInvalid1(_ context.Context, _ int) (TestStruct1, error) {
return TestStruct1{}, nil
}
func DBTestFuncInvalid2(_ context.Context, _ TestStruct2) TestStruct1 {
return TestStruct1{}
}
func DBTestFuncInvalid3(_ context.Context, arr ...TestStruct2) (TestStruct1, error) {
return TestStruct1{}, nil
}
func DBTestFuncInvalid4(_ context.Context, _ *TestStruct2) (TestStruct1, error) {
return TestStruct1{}, nil
}
func DBTestFuncInvalid5(_ context.Context, _ TestStruct1) (TestStruct1, error) {
return TestStruct1{}, nil
}
func DBTestFuncInvalid6(_ context.Context, _ TestStruct2) (int, error) {
return 0, nil
}
func DBTestFuncInvalid7(_ context.Context, _ TestStruct1) (TestStruct1, int) {
return TestStruct1{}, 0
}
func DBTestFuncInvalid8(_ context.Context, _ TestStruct1) (TestStruct1, TestInter) {
return TestStruct1{}, nil
}
func testNew(t *testing.T) *db {
dbuild := New()
d, ok := dbuild.(*db)
if !ok {
assert.Fail(t, "New Should return an object of *db")
}
return d
}