예제 #1
0
package mcredis_test

import (
	"errors"

	"github.com/garyburd/redigo/redis"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/sendgrid/mcredis"
	"github.com/sendgrid/mcredis/fake"
)

var _ = Describe("RedisCommander", func() {
	var (
		commander      *mcredis.RedisInstance
		fakeConnection *fake.FakeConnection
	)

	BeforeEach(func() {
		fakeConnection = &fake.FakeConnection{}
		commander = &mcredis.RedisInstance{fake.NewFakeCommander()}
	})

	Describe("#Set", func() {
		It("calls SET on the redis connection", func() {
			var setCalled bool
			fakeConnection.RespondToDo(func(command string, args ...interface{}) (interface{}, error) {
				setCalled = true
				Expect(command).To(Equal("SET"))
				Expect(args[0]).To(HaveLen(2))
				Expect(args[0].([]interface{})[0]).To(Equal("my key"))
예제 #2
0
	"errors"

	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/sendgrid/mcredis"
	"github.com/sendgrid/mcredis/fake"
)

var _ = Describe("RedisSentinel", func() {

	var (
		dialSentinelCount int
		dialMasterCount   int
		redisDialer       *fake.FakeDialer
		redis             *fake.FakeConnection
		sentinel          *mcredis.RedisInstance
		roleCalled        bool
	)

	BeforeEach(func() {
		redisDialer = fake.NewFakeDialer()
		redis = &fake.FakeConnection{}
		dialSentinelCount = 0
		dialMasterCount = 0
		roleCalled = false

		redisDialer.RespondToDial(func(url, address string) (*fake.FakeConnection, error) {
			dialMasterCount++
			if address == "badMasterAddr:port" {
				return nil, errors.New("master connection error")