-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathping_test.go
61 lines (51 loc) · 1.18 KB
/
ping_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
// SPDX-License-Identifier: Apache-2.0
package redis
import (
"context"
"fmt"
"github.com/alicebob/miniredis/v2"
"testing"
"time"
)
func TestRedis_Ping_Good(t *testing.T) {
_redis, err := miniredis.Run()
if err != nil {
t.Errorf("unable to create miniredis instance: %v", err)
}
defer _redis.Close()
// setup redis mock
goodRedis, err := New(
WithAddress(fmt.Sprintf("redis://%s", _redis.Addr())),
WithChannels("foo"),
WithCluster(false),
WithTimeout(5*time.Second),
)
if err != nil {
t.Errorf("unable to create queue service: %v", err)
}
// run tests
err = goodRedis.Ping(context.Background())
if err != nil {
t.Errorf("Ping returned err: %v", err)
}
}
func TestRedis_Ping_Bad(t *testing.T) {
_redis, err := miniredis.Run()
if err != nil {
t.Errorf("unable to create miniredis instance: %v", err)
}
defer _redis.Close()
// setup redis mock
badRedis, _ := New(
WithAddress(fmt.Sprintf("redis://%s", _redis.Addr())),
WithChannels("foo"),
WithCluster(false),
WithTimeout(5*time.Second),
)
_redis.SetError("not aiv")
// run tests
err = badRedis.Ping(context.Background())
if err == nil {
t.Errorf("Ping should have returned err: %v", err)
}
}