-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreplay_test.go
75 lines (57 loc) · 1.71 KB
/
replay_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
// @author: Brian Wojtczak
// @copyright: 2024 by Brian Wojtczak
// @license: BSD-style license found in the LICENSE file
package altcha
import (
"log"
"sync"
"testing"
)
func TestBanSignature(t *testing.T) {
// Reset bannedSignatures for testing
bannedSignatures = [][]string{}
signature := "testSignature"
BanSignature(signature)
if len(bannedSignatures) == 0 || len(bannedSignatures[0]) == 0 || bannedSignatures[0][0] != signature {
t.Errorf("BanSignature failed to add signature")
}
log.Printf("bannedSignatures: %v", bannedSignatures)
}
func TestBanSignatureEmpty(t *testing.T) {
// Reset bannedSignatures for testing
bannedSignatures = [][]string{}
BanSignature("")
if len(bannedSignatures) != 0 {
t.Errorf("BanSignature should not add empty signature")
}
}
func TestIsSignatureBanned(t *testing.T) {
// Reset bannedSignatures for testing
bannedSignatures = [][]string{{"bannedSignature"}}
if !IsSignatureBanned("bannedSignature") {
t.Errorf("IsSignatureBanned failed to recognize a banned signature")
}
if !IsSignatureBanned("") {
t.Errorf("IsSignatureBanned failed to recognize an empty signature")
}
if IsSignatureBanned("unbannedSignature") {
t.Errorf("IsSignatureBanned incorrectly identified an unbanned signature")
}
}
func TestConcurrency(t *testing.T) {
// Reset bannedSignatures for testing
bannedSignatures = [][]string{}
var wg sync.WaitGroup
signatures := []string{"sig1", "sig2", "sig3"}
for _, sig := range signatures {
wg.Add(1)
go func(signature string) {
defer wg.Done()
BanSignature(signature)
}(sig)
}
wg.Wait()
if len(bannedSignatures) == 0 || len(bannedSignatures[0]) != len(signatures) {
t.Errorf("BanSignature failed to handle concurrent access")
}
}