@@ -28,12 +28,8 @@ func nextPort() int32 {
28
28
}
29
29
30
30
func TestSpawnEtcdRaft (t * testing.T ) {
31
-
32
31
gt := NewGomegaWithT (t )
33
32
34
- cwd , err := filepath .Abs ("." )
35
- gt .Expect (err ).NotTo (HaveOccurred ())
36
-
37
33
// Set the fabric root folder for easy navigation to sampleconfig folder
38
34
fabricRootDir , err := filepath .Abs (filepath .Join (".." , ".." , ".." ))
39
35
gt .Expect (err ).NotTo (HaveOccurred ())
@@ -55,7 +51,7 @@ func TestSpawnEtcdRaft(t *testing.T) {
55
51
defer os .RemoveAll (tempDir )
56
52
57
53
t .Run ("Invalid bootstrap block" , func (t * testing.T ) {
58
- testEtcdRaftOSNFailureInvalidBootstrapBlock (NewGomegaWithT (t ), tempDir , orderer , fabricRootDir )
54
+ testEtcdRaftOSNFailureInvalidBootstrapBlock (NewGomegaWithT (t ), tempDir , orderer , fabricRootDir , configtxgen )
59
55
})
60
56
61
57
t .Run ("TLS disabled single listener" , func (t * testing.T ) {
@@ -81,17 +77,17 @@ func TestSpawnEtcdRaft(t *testing.T) {
81
77
gt .Expect (err ).NotTo (HaveOccurred ())
82
78
defer os .RemoveAll (tempDir )
83
79
84
- testEtcdRaftOSNSuccess (gt , tempDir , configtxgen , cwd , orderer , fabricRootDir )
80
+ testEtcdRaftOSNSuccess (gt , tempDir , configtxgen , orderer , fabricRootDir )
85
81
})
86
82
})
87
83
}
88
84
89
- func createBootstrapBlock (gt * GomegaWithT , tempDir , configtxgen , cwd string ) string {
90
- // Create the genesis block for the system channel
85
+ func createBootstrapBlock (gt * GomegaWithT , tempDir , configtxgen , channel , profile string ) string {
86
+ // create a genesis block for the specified channel and profile
91
87
genesisBlockPath := filepath .Join (tempDir , "genesis.block" )
92
- cmd := exec .Command (configtxgen , "-channelID" , "system" , "-profile" , "SampleDevModeEtcdRaft" ,
88
+ cmd := exec .Command (configtxgen , "-channelID" , channel , "-profile" , profile ,
93
89
"-outputBlock" , genesisBlockPath )
94
- cmd .Env = append (cmd .Env , fmt . Sprintf ( "FABRIC_CFG_PATH=%s" , filepath . Join ( cwd , " testdata")) )
90
+ cmd .Env = append (cmd .Env , "FABRIC_CFG_PATH=testdata" )
95
91
configtxgenProcess , err := gexec .Start (cmd , nil , nil )
96
92
gt .Expect (err ).NotTo (HaveOccurred ())
97
93
gt .Eventually (configtxgenProcess , time .Minute ).Should (gexec .Exit (0 ))
@@ -100,8 +96,8 @@ func createBootstrapBlock(gt *GomegaWithT, tempDir, configtxgen, cwd string) str
100
96
return genesisBlockPath
101
97
}
102
98
103
- func testEtcdRaftOSNSuccess (gt * GomegaWithT , tempDir , configtxgen , cwd , orderer , fabricRootDir string ) {
104
- genesisBlockPath := createBootstrapBlock (gt , tempDir , configtxgen , cwd )
99
+ func testEtcdRaftOSNSuccess (gt * GomegaWithT , tempDir , configtxgen , orderer , fabricRootDir string ) {
100
+ genesisBlockPath := createBootstrapBlock (gt , tempDir , configtxgen , "system" , "SampleEtcdRaftSystemChannel" )
105
101
106
102
// Launch the OSN
107
103
ordererProcess := launchOrderer (gt , orderer , tempDir , genesisBlockPath , fabricRootDir )
@@ -126,9 +122,9 @@ func testEtcdRaftOSNSuccess(gt *GomegaWithT, tempDir, configtxgen, cwd, orderer,
126
122
gt .Eventually (ordererProcess .Err , time .Minute ).Should (gbytes .Say ("becomeLeader" ))
127
123
}
128
124
129
- func testEtcdRaftOSNFailureInvalidBootstrapBlock (gt * GomegaWithT , tempDir , orderer , fabricRootDir string ) {
130
- // Grab an application channel genesis block
131
- genesisBlockPath := filepath . Join ( filepath . Join ( "testdata " , "mychannel.block" ) )
125
+ func testEtcdRaftOSNFailureInvalidBootstrapBlock (gt * GomegaWithT , tempDir , orderer , fabricRootDir , configtxgen string ) {
126
+ // create an application channel genesis block
127
+ genesisBlockPath := createBootstrapBlock ( gt , tempDir , configtxgen , "mychannel " , "SampleOrgChannel" )
132
128
genesisBlockBytes , err := ioutil .ReadFile (genesisBlockPath )
133
129
gt .Expect (err ).NotTo (HaveOccurred ())
134
130
@@ -146,10 +142,7 @@ func testEtcdRaftOSNFailureInvalidBootstrapBlock(gt *GomegaWithT, tempDir, order
146
142
}
147
143
148
144
func testEtcdRaftOSNNoTLSSingleListener (gt * GomegaWithT , tempDir , orderer , fabricRootDir string , configtxgen string ) {
149
- cwd , err := filepath .Abs ("." )
150
- gt .Expect (err ).NotTo (HaveOccurred ())
151
-
152
- genesisBlockPath := createBootstrapBlock (gt , tempDir , configtxgen , cwd )
145
+ genesisBlockPath := createBootstrapBlock (gt , tempDir , configtxgen , "system" , "SampleEtcdRaftSystemChannel" )
153
146
154
147
cmd := exec .Command (orderer )
155
148
cmd .Env = []string {
@@ -169,10 +162,10 @@ func testEtcdRaftOSNNoTLSSingleListener(gt *GomegaWithT, tempDir, orderer, fabri
169
162
}
170
163
171
164
func testEtcdRaftOSNNoTLSDualListener (gt * GomegaWithT , tempDir , orderer , fabricRootDir string , configtxgen string ) {
172
- cwd , err := filepath . Abs ( "." )
165
+ cwd , err := os . Getwd ( )
173
166
gt .Expect (err ).NotTo (HaveOccurred ())
174
167
175
- genesisBlockPath := createBootstrapBlock (gt , tempDir , configtxgen , cwd )
168
+ genesisBlockPath := createBootstrapBlock (gt , tempDir , configtxgen , "system" , "SampleEtcdRaftSystemChannel" )
176
169
177
170
cmd := exec .Command (orderer )
178
171
cmd .Env = []string {
@@ -185,11 +178,11 @@ func testEtcdRaftOSNNoTLSDualListener(gt *GomegaWithT, tempDir, orderer, fabricR
185
178
fmt .Sprintf ("ORDERER_GENERAL_GENESISFILE=%s" , genesisBlockPath ),
186
179
fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_LISTENPORT=%d" , nextPort ()),
187
180
"ORDERER_GENERAL_CLUSTER_LISTENADDRESS=127.0.0.1" ,
188
- fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=%s" , filepath .Join (cwd , "testdata" , "tls" , "server.crt" )),
189
- fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY=%s" , filepath .Join (cwd , "testdata" , "tls" , "server.key" )),
190
- fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=%s" , filepath .Join (cwd , "testdata" , "tls" , "server.crt" )),
191
- fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=%s" , filepath .Join (cwd , "testdata" , "tls" , "server.key" )),
192
- fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_ROOTCAS=[%s]" , filepath .Join (cwd , "testdata" , "tls" , "ca.crt" )),
181
+ fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=%s" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "server.crt" )),
182
+ fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY=%s" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "server.key" )),
183
+ fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=%s" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "server.crt" )),
184
+ fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=%s" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "server.key" )),
185
+ fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_ROOTCAS=[%s]" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "ca.crt" )),
193
186
fmt .Sprintf ("ORDERER_CONSENSUS_WALDIR=%s" , filepath .Join (tempDir , "wal" )),
194
187
fmt .Sprintf ("ORDERER_CONSENSUS_SNAPDIR=%s" , filepath .Join (tempDir , "snapshot" )),
195
188
fmt .Sprintf ("FABRIC_CFG_PATH=%s" , filepath .Join (fabricRootDir , "sampleconfig" )),
@@ -204,7 +197,7 @@ func testEtcdRaftOSNNoTLSDualListener(gt *GomegaWithT, tempDir, orderer, fabricR
204
197
}
205
198
206
199
func launchOrderer (gt * GomegaWithT , orderer , tempDir , genesisBlockPath , fabricRootDir string ) * gexec.Session {
207
- cwd , err := filepath . Abs ( "." )
200
+ cwd , err := os . Getwd ( )
208
201
gt .Expect (err ).NotTo (HaveOccurred ())
209
202
210
203
// Launch the orderer process
@@ -220,14 +213,14 @@ func launchOrderer(gt *GomegaWithT, orderer, tempDir, genesisBlockPath, fabricRo
220
213
fmt .Sprintf ("ORDERER_GENERAL_GENESISFILE=%s" , genesisBlockPath ),
221
214
fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_LISTENPORT=%d" , nextPort ()),
222
215
"ORDERER_GENERAL_CLUSTER_LISTENADDRESS=127.0.0.1" ,
223
- fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=%s" , filepath .Join (cwd , "testdata" , "tls" , "server.crt" )),
224
- fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY=%s" , filepath .Join (cwd , "testdata" , "tls" , "server.key" )),
225
- fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=%s" , filepath .Join (cwd , "testdata" , "tls" , "server.crt" )),
226
- fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=%s" , filepath .Join (cwd , "testdata" , "tls" , "server.key" )),
227
- fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_ROOTCAS=[%s]" , filepath .Join (cwd , "testdata" , "tls" , "ca.crt" )),
228
- fmt .Sprintf ("ORDERER_GENERAL_TLS_ROOTCAS=[%s]" , filepath .Join (cwd , "testdata" , "tls" , "ca.crt" )),
229
- fmt .Sprintf ("ORDERER_GENERAL_TLS_CERTIFICATE=%s" , filepath .Join (cwd , "testdata" , "tls" , "server.crt" )),
230
- fmt .Sprintf ("ORDERER_GENERAL_TLS_PRIVATEKEY=%s" , filepath .Join (cwd , "testdata" , "tls" , "server.key" )),
216
+ fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=%s" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "server.crt" )),
217
+ fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY=%s" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "server.key" )),
218
+ fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=%s" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "server.crt" )),
219
+ fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=%s" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "server.key" )),
220
+ fmt .Sprintf ("ORDERER_GENERAL_CLUSTER_ROOTCAS=[%s]" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "ca.crt" )),
221
+ fmt .Sprintf ("ORDERER_GENERAL_TLS_ROOTCAS=[%s]" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "ca.crt" )),
222
+ fmt .Sprintf ("ORDERER_GENERAL_TLS_CERTIFICATE=%s" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "server.crt" )),
223
+ fmt .Sprintf ("ORDERER_GENERAL_TLS_PRIVATEKEY=%s" , filepath .Join (cwd , "testdata" , "example.com" , " tls" , "server.key" )),
231
224
fmt .Sprintf ("ORDERER_CONSENSUS_WALDIR=%s" , filepath .Join (tempDir , "wal" )),
232
225
fmt .Sprintf ("ORDERER_CONSENSUS_SNAPDIR=%s" , filepath .Join (tempDir , "snapshot" )),
233
226
fmt .Sprintf ("FABRIC_CFG_PATH=%s" , filepath .Join (fabricRootDir , "sampleconfig" )),
0 commit comments