-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbiri_test.go
86 lines (69 loc) · 1.81 KB
/
biri_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package biri
import (
"strings"
"testing"
"time"
)
func TestGetClient(t *testing.T) {
// Add a cached proxy
reAddedProxies = append(reAddedProxies, Proxy{})
// Create a channel to signal the timeout
timeout := time.After(5 * time.Second) // Adjust the timeout duration as needed
// Create a channel to receive the result from the test function
done := make(chan struct{})
// Execute the test function in a goroutine
go func() {
client := GetClient()
t.Log(client)
if client == nil {
t.Error("Go no client")
}
// Call the test function here
// For example: myResult := myFunction()
// (Replace the above line with the actual test function call)
// Signal that the test function is done
close(done)
}()
// Use a select statement to wait for either the test to finish or the timeout
select {
case <-done:
// Test completed successfully
// Add any required assertions or checks here
case <-timeout:
// Test took too long to complete
t.Error("Test timeout")
}
}
func TestReadd(t *testing.T) {
reAddedProxies = reAddedProxies[:0]
p := &Proxy{}
p.Readd()
if len(reAddedProxies) != 1 {
t.Error("We added only one proxy")
}
}
func TestBanShouldCleanCache(t *testing.T) {
dummyProxy := Proxy{Info: "dummy"}
reAddedProxies = append(reAddedProxies, dummyProxy)
go dummyProxy.Ban()
banned := <-banProxy
if banned != dummyProxy.Info {
t.Error("Banned a other proxy")
}
for _, proxy := range reAddedProxies {
if proxy.Info == dummyProxy.Info {
t.Error(dummyProxy.Info, "should be banned")
}
}
}
func TestGetProxy(t *testing.T) {
Config.PingServer = "https://github.com"
go getProxy()
first := <-availableProxies
if strings.Count(first.Info, ".") != 3 {
t.Errorf("Error in ip %v", first)
}
if !strings.Contains(first.Info, ":") {
t.Errorf("Error in port %v", first)
}
}