This repository has been archived by the owner on Aug 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
redis_utils_test.go
110 lines (105 loc) · 2.35 KB
/
redis_utils_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"reflect"
"testing"
)
var testUriCases = []struct {
uriString string
expected *RedisServer
description string
}{
{
uriString: "redis://localhost:6379",
expected: &RedisServer{
Host: "localhost",
Port: "6379",
hostname: "localhost:6379",
Db: "0",
Pass: "",
},
description: "typical case",
},
{
uriString: "redis://redisproviders.com:12345/4",
expected: &RedisServer{
Host: "redisproviders.com",
Port: "12345",
hostname: "redisproviders.com:12345",
Db: "4",
Pass: "",
},
description: "host, port, db",
},
{
uriString: "redis://10.0.0.1",
expected: &RedisServer{
Host: "10.0.0.1",
Port: "6379",
hostname: "10.0.0.1:6379",
Db: "0",
Pass: "",
},
description: "host-only ip (guess default port and db)",
},
{
uriString: "redis://10.0.0.1",
expected: &RedisServer{
Host: "10.0.0.1",
Port: "6379",
hostname: "10.0.0.1:6379",
Db: "0",
Pass: "",
},
description: "with password (no username)",
},
{
uriString: "redis://oakland:ratchets@redis.bitly.com:999/1",
expected: &RedisServer{
Host: "redis.bitly.com",
Port: "999",
hostname: "redis.bitly.com:999",
Db: "1",
Pass: "ratchets",
},
description: "everything URI (username should be ignored)",
},
}
var testRawCases = []struct {
rawString string
expected *RedisServer
description string
}{
{
rawString: "localhost:6379:1",
expected: &RedisServer{
Host: "localhost",
Port: "6379",
hostname: "localhost:6379",
Db: "1",
Pass: "",
},
description: "typical case (all fields)",
},
}
func TestNewRedisServerFromUri(t *testing.T) {
for _, tt := range testUriCases {
expected := tt.expected
actual := NewRedisServerFromUri(tt.uriString)
if reflect.DeepEqual(expected, actual) {
t.Logf("PASS: %s", tt.description)
} else {
t.Errorf("FAIL: %s, expected: %+v, actual: %+v", tt.description, expected, actual)
}
}
}
func TestNewRedisServerFromRaw(t *testing.T) {
for _, tt := range testRawCases {
expected := tt.expected
actual := NewRedisServerFromRaw(tt.rawString)
if reflect.DeepEqual(expected, actual) {
t.Logf("PASS: %s", tt.description)
} else {
t.Errorf("FAIL: %s, expected: %+v, actual: %+v", tt.description, expected, actual)
}
}
}