File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ package redisdb
2+
3+ import (
4+ "fmt"
5+ "github.com/go-redis/redis/v8"
6+ "github.com/stretchr/testify/assert"
7+ "testing"
8+ )
9+
10+ var redisOptions = & redis.Options {
11+ Addr : "localhost:6379" ,
12+ Password : "" ,
13+ DB : 0 ,
14+ }
15+
16+ func TestNewRedisDB_WhenOptionsOk_ThenCreateClient (t * testing.T ) {
17+ got := NewRedisDB (redisOptions )
18+ got .Close ()
19+
20+ assert .NotNil (t , got )
21+ assert .Equal (t , redisOptions .Addr , got .Options ().Addr )
22+ assert .Equal (t , redisOptions .Password , got .Options ().Password )
23+ assert .Equal (t , redisOptions .DB , got .Options ().DB )
24+ }
25+
26+ func TestNewRedisDB_WhenOptionsNil_ThenPanic (t * testing.T ) {
27+ defer func () {
28+ if r := recover (); r != nil {
29+ assert .Equal (t , fmt .Sprint ("runtime error: invalid memory address or nil pointer dereference" ), fmt .Sprint (r ))
30+ }
31+ }()
32+ NewRedisDB (nil )
33+ }
34+
35+ func TestNewRedisDB_WhenOptionsContainBadAddr_ThenPanic (t * testing.T ) {
36+ defer func () {
37+ if r := recover (); r != nil {
38+ assert .Equal (t , fmt .Sprintln ("Redis connection error dial tcp: lookup awdawdaw: no such host" ), fmt .Sprint (r ))
39+ }
40+ }()
41+ NewRedisDB (& redis.Options {
42+ Addr : "bad:6379" ,
43+ Password : "" ,
44+ DB : 0 ,
45+ })
46+ }
You can’t perform that action at this time.
0 commit comments