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
|
// +build !go1.7
package redisc
import (
"testing"
"github.com/gomodule/redigo/redis"
"github.com/mna/redisc/redistest"
"github.com/stretchr/testify/assert"
)
// TestGetPool
func TestGetPool(t *testing.T) {
s := redistest.StartMockServer(t, func(cmd string, args ...string) interface{} {
return nil
})
defer s.Close()
p := &redis.Pool{
MaxActive: 1,
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", s.Addr)
},
}
c := Cluster{}
// fist connection is OK
conn, err := c.getFromPool(p)
if assert.NoError(t, err) {
defer conn.Close()
}
// second connection should be failed because we only have 1 MaxActive
_, err = c.getFromPool(p)
assert.Error(t, err)
}
|