-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions_test.go
77 lines (67 loc) · 1.22 KB
/
functions_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
package goentities
import (
"testing"
"github.com/stretchr/testify/assert"
)
type input struct {
IntField int
}
type output struct {
IntField int32 `entity:"IntField"`
// Fields to be calculated by functions
FuncField1 int `method:"FuncFieldOne"`
}
// let's take a bussiness logic that FuncField1 is 10X of IntField
func (i output) FuncFieldOne() int {
i.FuncField1 = int(i.IntField) * 10
return i.FuncField1
}
func Test_FunctionFields(t *testing.T) {
tests := []struct {
name string
input input
outputType output
want output
}{
{
name: "test 1",
input: input{
IntField: -5,
},
outputType: output{},
want: output{
IntField: -5,
FuncField1: -50,
},
},
{
name: "test 2",
input: input{
IntField: 0,
},
outputType: output{},
want: output{
IntField: 0,
FuncField1: 0,
},
},
{
name: "test 3",
input: input{
IntField: 11,
},
outputType: output{},
want: output{
IntField: 11,
FuncField1: 110,
},
},
}
t.Parallel()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Present(tt.input, tt.outputType).(output)
assert.Equal(t, tt.want, got, "ouput does not matches")
})
}
}