@@ -21,13 +21,17 @@ import (
21
21
"os"
22
22
"path/filepath"
23
23
"testing"
24
+ "time"
24
25
25
26
"github.com/hyperledger/fabric/peer/common"
26
27
pb "github.com/hyperledger/fabric/protos/peer"
28
+ "github.com/spf13/viper"
27
29
"github.com/stretchr/testify/assert"
28
30
)
29
31
30
32
func TestMissingBlockFile (t * testing.T ) {
33
+ defer resetFlags ()
34
+
31
35
resetFlags ()
32
36
33
37
cmd := joinCmd (nil )
@@ -39,6 +43,8 @@ func TestMissingBlockFile(t *testing.T) {
39
43
}
40
44
41
45
func TestJoin (t * testing.T ) {
46
+ defer resetFlags ()
47
+
42
48
InitMSP ()
43
49
resetFlags ()
44
50
@@ -56,10 +62,10 @@ func TestJoin(t *testing.T) {
56
62
Endorsement : & pb.Endorsement {},
57
63
}
58
64
59
- mockEndorerClient := common .GetMockEndorserClient (mockResponse , nil )
65
+ mockEndorserClient := common .GetMockEndorserClient (mockResponse , nil )
60
66
61
67
mockCF := & ChannelCmdFactory {
62
- EndorserClient : mockEndorerClient ,
68
+ EndorserClient : mockEndorserClient ,
63
69
BroadcastFactory : mockBroadcastClientFactory ,
64
70
Signer : signer ,
65
71
}
@@ -74,6 +80,8 @@ func TestJoin(t *testing.T) {
74
80
}
75
81
76
82
func TestJoinNonExistentBlock (t * testing.T ) {
83
+ defer resetFlags ()
84
+
77
85
InitMSP ()
78
86
resetFlags ()
79
87
@@ -87,10 +95,10 @@ func TestJoinNonExistentBlock(t *testing.T) {
87
95
Endorsement : & pb.Endorsement {},
88
96
}
89
97
90
- mockEndorerClient := common .GetMockEndorserClient (mockResponse , nil )
98
+ mockEndorserClient := common .GetMockEndorserClient (mockResponse , nil )
91
99
92
100
mockCF := & ChannelCmdFactory {
93
- EndorserClient : mockEndorerClient ,
101
+ EndorserClient : mockEndorserClient ,
94
102
BroadcastFactory : mockBroadcastClientFactory ,
95
103
Signer : signer ,
96
104
}
@@ -108,6 +116,8 @@ func TestJoinNonExistentBlock(t *testing.T) {
108
116
}
109
117
110
118
func TestBadProposalResponse (t * testing.T ) {
119
+ defer resetFlags ()
120
+
111
121
InitMSP ()
112
122
resetFlags ()
113
123
@@ -122,10 +132,10 @@ func TestBadProposalResponse(t *testing.T) {
122
132
Endorsement : & pb.Endorsement {},
123
133
}
124
134
125
- mockEndorerClient := common .GetMockEndorserClient (mockResponse , nil )
135
+ mockEndorserClient := common .GetMockEndorserClient (mockResponse , nil )
126
136
127
137
mockCF := & ChannelCmdFactory {
128
- EndorserClient : mockEndorerClient ,
138
+ EndorserClient : mockEndorserClient ,
129
139
BroadcastFactory : mockBroadcastClientFactory ,
130
140
Signer : signer ,
131
141
}
@@ -141,14 +151,19 @@ func TestBadProposalResponse(t *testing.T) {
141
151
assert .Error (t , err , "expected join command to fail" )
142
152
assert .IsType (t , ProposalFailedErr (err .Error ()), err , "expected error type of ProposalFailedErr" )
143
153
}
154
+
144
155
func TestJoinNilCF (t * testing.T ) {
156
+ defer viper .Reset ()
157
+ defer resetFlags ()
158
+
145
159
InitMSP ()
146
160
resetFlags ()
147
161
148
162
dir , err := ioutil .TempDir ("/tmp" , "jointest" )
149
163
assert .NoError (t , err , "Could not create the directory %s" , dir )
150
164
mockblockfile := filepath .Join (dir , "mockjointest.block" )
151
165
defer os .RemoveAll (dir )
166
+ viper .Set ("peer.client.connTimeout" , 10 * time .Millisecond )
152
167
cmd := joinCmd (nil )
153
168
AddFlags (cmd )
154
169
args := []string {"-b" , mockblockfile }
0 commit comments