@@ -9,14 +9,18 @@ import (
9
9
)
10
10
11
11
func TestGetConfigData (t * testing.T ) {
12
- config := types.Configurations {
12
+ nilConfig := types.Configurations {
13
13
Provider : "" ,
14
14
GasMultiplier : 0 ,
15
15
BufferPercent : 0 ,
16
16
WaitTime : 0 ,
17
17
LogLevel : "" ,
18
18
GasLimitMultiplier : 0 ,
19
19
RPCTimeout : 0 ,
20
+ HTTPTimeout : 0 ,
21
+ LogFileMaxSize : 0 ,
22
+ LogFileMaxBackups : 0 ,
23
+ LogFileMaxAge : 0 ,
20
24
}
21
25
22
26
configData := types.Configurations {
@@ -27,6 +31,7 @@ func TestGetConfigData(t *testing.T) {
27
31
LogLevel : "debug" ,
28
32
GasLimitMultiplier : 3 ,
29
33
RPCTimeout : 10 ,
34
+ HTTPTimeout : 10 ,
30
35
LogFileMaxSize : 5 ,
31
36
LogFileMaxBackups : 10 ,
32
37
LogFileMaxAge : 30 ,
@@ -48,6 +53,8 @@ func TestGetConfigData(t *testing.T) {
48
53
gasLimit float32
49
54
rpcTimeout int64
50
55
rpcTimeoutErr error
56
+ httpTimeout int64
57
+ httpTimeoutErr error
51
58
gasLimitErr error
52
59
logFileMaxSize int
53
60
logFileMaxSizeErr error
@@ -72,6 +79,7 @@ func TestGetConfigData(t *testing.T) {
72
79
logLevel : "debug" ,
73
80
gasLimit : 3 ,
74
81
rpcTimeout : 10 ,
82
+ httpTimeout : 10 ,
75
83
logFileMaxSize : 5 ,
76
84
logFileMaxBackups : 10 ,
77
85
logFileMaxAge : 30 ,
@@ -84,65 +92,73 @@ func TestGetConfigData(t *testing.T) {
84
92
args : args {
85
93
providerErr : errors .New ("provider error" ),
86
94
},
87
- want : config ,
95
+ want : nilConfig ,
88
96
wantErr : errors .New ("provider error" ),
89
97
},
90
98
{
91
99
name : "Test 3: When there is an error in getting gasMultiplier" ,
92
100
args : args {
93
101
gasMultiplierErr : errors .New ("gasMultiplier error" ),
94
102
},
95
- want : config ,
103
+ want : nilConfig ,
96
104
wantErr : errors .New ("gasMultiplier error" ),
97
105
},
98
106
{
99
107
name : "Test 4: When there is an error in getting bufferPercent" ,
100
108
args : args {
101
109
bufferPercentErr : errors .New ("bufferPercent error" ),
102
110
},
103
- want : config ,
111
+ want : nilConfig ,
104
112
wantErr : errors .New ("bufferPercent error" ),
105
113
},
106
114
{
107
115
name : "Test 5: When there is an error in getting waitTime" ,
108
116
args : args {
109
117
waitTimeErr : errors .New ("waitTime error" ),
110
118
},
111
- want : config ,
119
+ want : nilConfig ,
112
120
wantErr : errors .New ("waitTime error" ),
113
121
},
114
122
{
115
123
name : "Test 6: When there is an error in getting gasPrice" ,
116
124
args : args {
117
125
gasPriceErr : errors .New ("gasPrice error" ),
118
126
},
119
- want : config ,
127
+ want : nilConfig ,
120
128
wantErr : errors .New ("gasPrice error" ),
121
129
},
122
130
{
123
131
name : "Test 7: When there is an error in getting logLevel" ,
124
132
args : args {
125
133
logLevelErr : errors .New ("logLevel error" ),
126
134
},
127
- want : config ,
135
+ want : nilConfig ,
128
136
wantErr : errors .New ("logLevel error" ),
129
137
},
130
138
{
131
139
name : "Test 8: When there is an error in getting gasLimit" ,
132
140
args : args {
133
141
gasLimitErr : errors .New ("gasLimit error" ),
134
142
},
135
- want : config ,
143
+ want : nilConfig ,
136
144
wantErr : errors .New ("gasLimit error" ),
137
145
},
138
146
{
139
147
name : "Test 9: When there is an error in getting rpcTimeout" ,
140
148
args : args {
141
149
rpcTimeoutErr : errors .New ("rpcTimeout error" ),
142
150
},
143
- want : config ,
151
+ want : nilConfig ,
144
152
wantErr : errors .New ("rpcTimeout error" ),
145
153
},
154
+ {
155
+ name : "Test 10: When there is an error in getting httpTimeout" ,
156
+ args : args {
157
+ httpTimeoutErr : errors .New ("httpTimeout error" ),
158
+ },
159
+ want : nilConfig ,
160
+ wantErr : errors .New ("httpTimeout error" ),
161
+ },
146
162
}
147
163
for _ , tt := range tests {
148
164
t .Run (tt .name , func (t * testing.T ) {
@@ -156,6 +172,7 @@ func TestGetConfigData(t *testing.T) {
156
172
cmdUtilsMock .On ("GetGasLimit" ).Return (tt .args .gasLimit , tt .args .gasLimitErr )
157
173
cmdUtilsMock .On ("GetBufferPercent" ).Return (tt .args .bufferPercent , tt .args .bufferPercentErr )
158
174
cmdUtilsMock .On ("GetRPCTimeout" ).Return (tt .args .rpcTimeout , tt .args .rpcTimeoutErr )
175
+ cmdUtilsMock .On ("GetHTTPTimeout" ).Return (tt .args .httpTimeout , tt .args .httpTimeoutErr )
159
176
cmdUtilsMock .On ("GetLogFileMaxSize" ).Return (tt .args .logFileMaxSize , tt .args .logFileMaxSizeErr )
160
177
cmdUtilsMock .On ("GetLogFileMaxBackups" ).Return (tt .args .logFileMaxBackups , tt .args .logFileMaxBackupsErr )
161
178
cmdUtilsMock .On ("GetLogFileMaxAge" ).Return (tt .args .logFileMaxAge , tt .args .logFileMaxAgeErr )
@@ -664,3 +681,62 @@ func TestGetRPCTimeout(t *testing.T) {
664
681
})
665
682
}
666
683
}
684
+
685
+ func TestGetHTTPTimeout (t * testing.T ) {
686
+ type args struct {
687
+ httpTimeout int64
688
+ httpTimeoutErr error
689
+ }
690
+ tests := []struct {
691
+ name string
692
+ args args
693
+ want int64
694
+ wantErr error
695
+ }{
696
+ {
697
+ name : "Test 1: When getHTTPTimeout function executes successfully" ,
698
+ args : args {
699
+ httpTimeout : 12 ,
700
+ },
701
+ want : 12 ,
702
+ wantErr : nil ,
703
+ },
704
+ {
705
+ name : "Test 2: When httpTimeout is 0" ,
706
+ args : args {
707
+ httpTimeout : 0 ,
708
+ },
709
+ want : 10 ,
710
+ wantErr : nil ,
711
+ },
712
+ {
713
+ name : "Test 3: When there is an error in getting httpTimeout" ,
714
+ args : args {
715
+ httpTimeoutErr : errors .New ("httpTimeout error" ),
716
+ },
717
+ want : 10 ,
718
+ wantErr : errors .New ("httpTimeout error" ),
719
+ },
720
+ }
721
+ for _ , tt := range tests {
722
+ t .Run (tt .name , func (t * testing.T ) {
723
+ SetUpMockInterfaces ()
724
+
725
+ flagSetMock .On ("GetRootInt64HTTPTimeout" ).Return (tt .args .httpTimeout , tt .args .httpTimeoutErr )
726
+ utils := & UtilsStruct {}
727
+ got , err := utils .GetHTTPTimeout ()
728
+ if got != tt .want {
729
+ t .Errorf ("getHTTPTimeout() got = %v, want %v" , got , tt .want )
730
+ }
731
+ if err == nil || tt .wantErr == nil {
732
+ if err != tt .wantErr {
733
+ t .Errorf ("Error for getHTTPTimeout function, got = %v, want = %v" , err , tt .wantErr )
734
+ }
735
+ } else {
736
+ if err .Error () != tt .wantErr .Error () {
737
+ t .Errorf ("Error for getHTTPTimeout function, got = %v, want = %v" , err , tt .wantErr )
738
+ }
739
+ }
740
+ })
741
+ }
742
+ }
0 commit comments