forked from Trendyol/sidecache
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver_test.go
More file actions
73 lines (68 loc) · 1.61 KB
/
server_test.go
File metadata and controls
73 lines (68 loc) · 1.61 KB
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
package server_test
import (
"net/url"
"testing"
"github.com/zeriontech/sidecache/pkg/server"
"go.uber.org/zap"
)
func TestGetLockKey(t *testing.T) {
logger, err := zap.NewDevelopment()
if err != nil {
t.FailNow()
}
testData := []struct {
name string
urlStr string
expected string
lockLocation server.Location
lockIndex int
lockKey string
}{
{
"path-1",
"http://localhost:1234/0x2d03f2b283fc90da454383afa8080293c8336448/info/?address=0x2d03f2b283fc90da454383afa8080293c8336448",
"lock:0x2d03f2b283fc90da454383afa8080293c8336448",
server.LocationPath,
1,
"",
},
{
"query-address",
"http://localhost:1234/api/v1/actions/?address=0x49131d39ead64a9e4912e641a6bd5fa7ae452f3f¤cy=usd&limit=500&offset=0&search_query=receive",
"lock:0x49131d39ead64a9e4912e641a6bd5fa7ae452f3f",
server.LocationQuery,
0,
"address",
},
{
"query-multiple-uses-min",
"http://localhost:1234/api/v1/actions/?address=0x49131d39ead64a9e4912e641a6bd5fa7ae452f3f&address=0x123&address=0x456",
"lock:0x123",
server.LocationQuery,
0,
"address",
},
}
for _, d := range testData {
t.Run(d.name, func(t *testing.T) {
u, err := url.Parse(d.urlStr)
if err != nil {
logger.Error("could not parse test url")
t.FailNow()
}
// setup
server.LockLocation = d.lockLocation
server.LockIndex = d.lockIndex
server.LockKey = d.lockKey
key := server.GetLockKey(logger, u)
if key != d.expected {
logger.Error(
"key mismatch",
zap.String("expected", d.expected),
zap.String("actual", key),
)
t.Fail()
}
})
}
}