1
1
package captchatoolsgo
2
2
3
3
import (
4
+ "context"
5
+ "errors"
4
6
"fmt"
7
+ "net/http"
5
8
"os"
6
9
"testing"
10
+ "time"
7
11
8
12
"github.com/joho/godotenv"
9
13
)
@@ -132,7 +136,7 @@ func Test2CaptchaGetV2(t *testing.T) {
132
136
for _ , c := range configs {
133
137
t .Run (c .Name , func (t * testing.T ) {
134
138
a := & Twocaptcha {c .Config }
135
- _ , err := a .getCaptchaAnswer ()
139
+ _ , err := a .getCaptchaAnswer (context . Background () )
136
140
if err != nil && ! c .ExpectError {
137
141
t .Fatalf (`getID() Error: %v , wanted: %v` , err , nil )
138
142
}
@@ -187,7 +191,7 @@ func Test2CaptchaGetV2Additional(t *testing.T) {
187
191
for _ , c := range configs {
188
192
t .Run (c .Name , func (t * testing.T ) {
189
193
a := & Twocaptcha {c .Config }
190
- _ , err := a .getCaptchaAnswer (c .AdditionalData )
194
+ _ , err := a .getCaptchaAnswer (context . Background (), c .AdditionalData )
191
195
if err != nil && ! c .ExpectError {
192
196
t .Fatalf (`getID() Error: %v , wanted: %v` , err , nil )
193
197
}
@@ -215,7 +219,7 @@ func Test2CaptchaGetV3(t *testing.T) {
215
219
for _ , c := range configs {
216
220
t .Run (c .Name , func (t * testing.T ) {
217
221
a := & Twocaptcha {c .Config }
218
- _ , err := a .getCaptchaAnswer ()
222
+ _ , err := a .getCaptchaAnswer (context . Background () )
219
223
if err != nil && ! c .ExpectError {
220
224
t .Fatalf (`getID() Error: %v , wanted: %v` , err , nil )
221
225
}
@@ -244,7 +248,7 @@ func Test2CaptchaGetImage(t *testing.T) {
244
248
for _ , c := range configs {
245
249
t .Run (c .Name , func (t * testing.T ) {
246
250
a := & Twocaptcha {c .Config }
247
- answer , err := a .getCaptchaAnswer (& AdditionalData {B64Img : c .Image })
251
+ answer , err := a .getCaptchaAnswer (context . Background (), & AdditionalData {B64Img : c .Image })
248
252
if err != nil && ! c .ExpectError {
249
253
t .Fatalf (`getID() Error: %v , wanted: %v` , err , nil )
250
254
}
@@ -255,3 +259,24 @@ func Test2CaptchaGetImage(t *testing.T) {
255
259
})
256
260
}
257
261
}
262
+
263
+ // go test -v -run ^TestSometing$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
264
+ func TestSometing (t * testing.T ) {
265
+ ctx , cancel := context .WithTimeout (context .Background (), 25 * time .Second )
266
+ defer cancel ()
267
+
268
+ reqToMake , _ := http .NewRequestWithContext (ctx , "GET" , "https://httpbin.org/delay/10" , nil )
269
+ c := http.Client {
270
+ Timeout : 5 * time .Second ,
271
+ }
272
+
273
+ _ , err := c .Do (reqToMake )
274
+ if err != nil {
275
+ fmt .Println (errors .Is (err , context .Canceled ))
276
+ fmt .Println (errors .Is (err , context .DeadlineExceeded ))
277
+ fmt .Printf ("%v || %T\n " , err , err )
278
+ return
279
+ }
280
+ t .Fatal ("Not supposed to be any error" )
281
+
282
+ }
0 commit comments