-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject_test.go
120 lines (107 loc) · 3.42 KB
/
inject_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
package gobpmn_hash_test
import (
"testing"
"github.com/stretchr/testify/assert"
gobpmn_hash "github.com/deemount/gobpmnHash"
"github.com/deemount/gobpmnModels/pkg/core"
)
/*
Note:
Test Process and TestEmbeddedProcess are two structs copied from the
gobpmnByExample package.
*/
// TestEmbeddedProcess is a struct that contains fields of type
// core.DefinitionsRepository and two anonymous embedded structs.
// It is a copy of the gobpmnByExample/example/01 package.
type TestEmbeddedProcess struct {
Def core.DefinitionsRepository
TestEmbeddedPool
TestEmbeddedTenant
}
// TestEmbeddedPool is a struct that contains fields of type
// gobpmn_hash.Injection and bool.
// It is embedded in the TestEmbeddedProcess struct.
type TestEmbeddedPool struct {
XYZIsExecutable bool
XYZProcess gobpmn_hash.Injection
}
// TestEmbeddedTenant is a struct that contains a field of type
// gobpmn_hash.Injection.
// It is embedded in the TestEmbeddedProcess struct.
type TestEmbeddedTenant struct {
XYZStartEvent gobpmn_hash.Injection
}
// TestProcess is a struct that contains fields of type
// core.DefinitionsRepository, gobpmn_hash.Injection, and bool.
// It is a copy of the gobpmnByExample/example/02 package.
type TestProcess struct {
Def core.DefinitionsRepository
IsExecutable bool
Process gobpmn_hash.Injection
StartEvent gobpmn_hash.Injection
FromStartEvent gobpmn_hash.Injection
Task gobpmn_hash.Injection
FromTask gobpmn_hash.Injection
EndEvent gobpmn_hash.Injection
}
// TestInjectConfig tests the injection of a bool type
// into the field IsExecutable of the struct TestProcess
// and TestEmbeddedPool.
// The field IsExecutable is set to false as default, but
// if reflected the field is set to true.
// In gobpmnHash, a Config consists of a reflected struct field
// which has a bool type.
// This test should pass if the field IsExecutable is expected
// set to true or false
func TestInjectConfig(t *testing.T) {
t.Run("p(TestProcess{}).IsExecutable expected true",
func(t *testing.T) {
hash := new(gobpmn_hash.Injection)
p := hash.Inject(TestProcess{}).(TestProcess)
got := p.IsExecutable
if assert.NotNil(t, p) {
assert.Equal(t, bool(true), got)
}
})
t.Run("p(TestProcess{}).IsExecutable expected false",
func(t *testing.T) {
hash := new(gobpmn_hash.Injection)
p := hash.Inject(TestProcess{}).(TestProcess)
got := p.IsExecutable
if assert.NotNil(t, p) {
assert.NotEqual(t, bool(false), got)
}
})
t.Run("p(TestEmbeddedProcess{}).IsExecutable expected true",
func(t *testing.T) {
hash := new(gobpmn_hash.Injection)
p := hash.Inject(TestEmbeddedProcess{}).(TestEmbeddedProcess)
got := p.XYZIsExecutable
if assert.NotNil(t, p) {
assert.Equal(t, bool(true), got)
}
})
t.Run("p(TestEmbeddedProcess{}).IsExecutable expected false",
func(t *testing.T) {
hash := new(gobpmn_hash.Injection)
p := hash.Inject(TestEmbeddedProcess{}).(TestEmbeddedProcess)
got := p.XYZIsExecutable
if assert.NotNil(t, p) {
assert.NotEqual(t, bool(false), got)
}
})
}
// BenchmarkInject ...
func BenchmarkInject(b *testing.B) {
for n := 0; n < b.N; n++ {
hash := new(gobpmn_hash.Injection)
_ = hash.Inject(TestProcess{}).(TestProcess)
}
}
// BenchmarkInjectEmbedded ...
func BenchmarkInjectEmbedded(b *testing.B) {
for n := 0; n < b.N; n++ {
hash := new(gobpmn_hash.Injection)
_ = hash.Inject(TestEmbeddedProcess{}).(TestEmbeddedProcess)
}
}