@@ -10,6 +10,8 @@ import (
10
10
"testing"
11
11
12
12
"github.com/hyperledger/fabric/core/config/configtest"
13
+ "github.com/hyperledger/fabric/protos/orderer/etcdraft"
14
+
13
15
"github.com/stretchr/testify/assert"
14
16
"github.com/stretchr/testify/require"
15
17
)
@@ -83,6 +85,29 @@ func TestConsensusSpecificInit(t *testing.T) {
83
85
devConfigDir , err := configtest .GetDevConfigDir ()
84
86
require .NoError (t , err )
85
87
88
+ t .Run ("nil orderer type" , func (t * testing.T ) {
89
+ profile := & Profile {
90
+ Orderer : & Orderer {
91
+ OrdererType : "" ,
92
+ },
93
+ }
94
+ profile .completeInitialization (devConfigDir )
95
+
96
+ assert .Equal (t , profile .Orderer .OrdererType , genesisDefaults .Orderer .OrdererType )
97
+ })
98
+
99
+ t .Run ("unknown orderer type" , func (t * testing.T ) {
100
+ profile := & Profile {
101
+ Orderer : & Orderer {
102
+ OrdererType : "unknown" ,
103
+ },
104
+ }
105
+
106
+ assert .Panics (t , func () {
107
+ profile .completeInitialization (devConfigDir )
108
+ })
109
+ })
110
+
86
111
t .Run ("solo" , func (t * testing.T ) {
87
112
profile := & Profile {
88
113
Orderer : & Orderer {
@@ -102,4 +127,137 @@ func TestConsensusSpecificInit(t *testing.T) {
102
127
profile .completeInitialization (devConfigDir )
103
128
assert .NotNil (t , profile .Orderer .Kafka .Brokers , "Kafka config settings should be set" )
104
129
})
130
+
131
+ t .Run ("raft" , func (t * testing.T ) {
132
+ makeProfile := func (consenters []* etcdraft.Consenter , options * etcdraft.Options ) * Profile {
133
+ return & Profile {
134
+ Orderer : & Orderer {
135
+ OrdererType : "etcdraft" ,
136
+ EtcdRaft : & etcdraft.Metadata {
137
+ Consenters : consenters ,
138
+ Options : options ,
139
+ },
140
+ },
141
+ }
142
+ }
143
+ t .Run ("EtcdRaft section not specified in profile" , func (t * testing.T ) {
144
+ profile := & Profile {
145
+ Orderer : & Orderer {
146
+ OrdererType : "etcdraft" ,
147
+ },
148
+ }
149
+
150
+ assert .Panics (t , func () {
151
+ profile .completeInitialization (devConfigDir )
152
+ })
153
+ })
154
+
155
+ t .Run ("nil consenter set" , func (t * testing.T ) { // should panic
156
+ profile := makeProfile (nil , nil )
157
+
158
+ assert .Panics (t , func () {
159
+ profile .completeInitialization (devConfigDir )
160
+ })
161
+ })
162
+
163
+ t .Run ("single consenter" , func (t * testing.T ) {
164
+ consenters := []* etcdraft.Consenter {
165
+ {
166
+ Host : "node-1.example.com" ,
167
+ Port : 7050 ,
168
+ ClientTlsCert : []byte ("path/to/client/cert" ),
169
+ ServerTlsCert : []byte ("path/to/server/cert" ),
170
+ },
171
+ }
172
+
173
+ t .Run ("invalid consenters specification" , func (t * testing.T ) {
174
+ failingConsenterSpecifications := []* etcdraft.Consenter {
175
+ { // missing Host
176
+ Port : 7050 ,
177
+ ClientTlsCert : []byte ("path/to/client/cert" ),
178
+ ServerTlsCert : []byte ("path/to/server/cert" ),
179
+ },
180
+ { // missing Port
181
+ Host : "node-1.example.com" ,
182
+ ClientTlsCert : []byte ("path/to/client/cert" ),
183
+ ServerTlsCert : []byte ("path/to/server/cert" ),
184
+ },
185
+ { // missing ClientTlsCert
186
+ Host : "node-1.example.com" ,
187
+ Port : 7050 ,
188
+ ServerTlsCert : []byte ("path/to/server/cert" ),
189
+ },
190
+ { // missing ServerTlsCert
191
+ Host : "node-1.example.com" ,
192
+ Port : 7050 ,
193
+ ClientTlsCert : []byte ("path/to/client/cert" ),
194
+ },
195
+ }
196
+
197
+ for _ , consenter := range failingConsenterSpecifications {
198
+ profile := makeProfile ([]* etcdraft.Consenter {consenter }, nil )
199
+
200
+ assert .Panics (t , func () {
201
+ profile .completeInitialization (devConfigDir )
202
+ })
203
+ }
204
+ })
205
+
206
+ t .Run ("nil Options" , func (t * testing.T ) {
207
+ profile := makeProfile (consenters , nil )
208
+ profile .completeInitialization (devConfigDir )
209
+
210
+ // need not be tested in subsequent tests
211
+ assert .NotNil (t , profile .Orderer .EtcdRaft , "EtcdRaft config settings should be set" )
212
+ assert .Equal (t , profile .Orderer .EtcdRaft .Consenters [0 ].ClientTlsCert , consenters [0 ].ClientTlsCert ,
213
+ "Client TLS cert path should be correctly set" )
214
+
215
+ // specific assertion for this test context
216
+ assert .Equal (t , profile .Orderer .EtcdRaft .Options , genesisDefaults .Orderer .EtcdRaft .Options ,
217
+ "Options should be set to the default value" )
218
+ })
219
+
220
+ t .Run ("heartbeat tick specified in Options" , func (t * testing.T ) {
221
+ heartbeatTick := uint32 (2 )
222
+ options := & etcdraft.Options { // partially set so that we can check that the other members are set to defaults
223
+ HeartbeatTick : heartbeatTick ,
224
+ }
225
+ profile := makeProfile (consenters , options )
226
+ profile .completeInitialization (devConfigDir )
227
+
228
+ // specific assertions for this test context
229
+ assert .Equal (t , profile .Orderer .EtcdRaft .Options .HeartbeatTick , heartbeatTick ,
230
+ "HeartbeatTick should be set to the specified value" )
231
+ assert .Equal (t , profile .Orderer .EtcdRaft .Options .ElectionTick , genesisDefaults .Orderer .EtcdRaft .Options .ElectionTick ,
232
+ "ElectionTick should be set to the default value" )
233
+ })
234
+
235
+ t .Run ("election tick specified in Options" , func (t * testing.T ) {
236
+ electionTick := uint32 (20 )
237
+ options := & etcdraft.Options { // partially set so that we can check that the other members are set to defaults
238
+ ElectionTick : electionTick ,
239
+ }
240
+ profile := makeProfile (consenters , options )
241
+ profile .completeInitialization (devConfigDir )
242
+
243
+ // specific assertions for this test context
244
+ assert .Equal (t , profile .Orderer .EtcdRaft .Options .ElectionTick , electionTick ,
245
+ "ElectionTick should be set to the specified value" )
246
+ assert .Equal (t , profile .Orderer .EtcdRaft .Options .HeartbeatTick , genesisDefaults .Orderer .EtcdRaft .Options .HeartbeatTick ,
247
+ "HeartbeatTick should be set to the default value" )
248
+ })
249
+
250
+ t .Run ("panic on invalid options" , func (t * testing.T ) {
251
+ options := & etcdraft.Options {
252
+ HeartbeatTick : 2 ,
253
+ ElectionTick : 1 ,
254
+ }
255
+ profile := makeProfile (consenters , options )
256
+
257
+ assert .Panics (t , func () {
258
+ profile .completeInitialization (devConfigDir )
259
+ })
260
+ })
261
+ })
262
+ })
105
263
}
0 commit comments