Exemplo n.º 1
0
func TestSetMirrorEnabled(t *testing.T) {
	mock, conn := PrepareRedisTest()

	cmd_publish := mock.Command("PUBLISH", string(database.MIRROR_UPDATE), redigomock.NewAnyData()).Expect("ok")

	cmd_enable := mock.Command("HMSET", "MIRROR_m1", "enabled", true).Expect("ok")
	SetMirrorEnabled(conn, "m1", true)

	if mock.Stats(cmd_enable) < 1 {
		t.Fatalf("Mirror not enabled")
	} else if mock.Stats(cmd_enable) > 1 {
		t.Fatalf("Mirror enabled more than once")
	}

	if mock.Stats(cmd_publish) < 1 {
		t.Fatalf("Event MIRROR_UPDATE not published")
	}

	mock.Command("HMSET", "MIRROR_m1", "enabled", true).ExpectError(redis.Error("blah"))
	if SetMirrorEnabled(conn, "m1", true) == nil {
		t.Fatalf("Error expected")
	}

	cmd_disable := mock.Command("HMSET", "MIRROR_m1", "enabled", false).Expect("ok")
	SetMirrorEnabled(conn, "m1", false)

	if mock.Stats(cmd_disable) != 1 {
		t.Fatalf("Mirror not disabled")
	} else if mock.Stats(cmd_disable) > 1 {
		t.Fatalf("Mirror disabled more than once")
	}

	if mock.Stats(cmd_publish) < 2 {
		t.Fatalf("Event MIRROR_UPDATE not published")
	}

	mock.Command("HMSET", "MIRROR_m1", "enabled", false).ExpectError(redis.Error("blah"))
	if SetMirrorEnabled(conn, "m1", false) == nil {
		t.Fatalf("Error expected")
	}
}
Exemplo n.º 2
0
func (suite *ByteQueueSuite) TestConcatAbortsOnCommandError() {
	err := redis.Error("oh no!")
	processor := &MockProcessor{}
	processor.On("Concat",
		mock.Anything, "bar", "foo").
		Return(err).Once()

	q := queue.NewByteQueue(suite.Pool, "foo")

	q.SetProcessor(processor)
	suite.Assert().Equal(q.Concat("bar"), err)

	processor.AssertExpectations(suite.T())
}
Exemplo n.º 3
0
func TestDisableMirror(t *testing.T) {
	mock, conn := PrepareRedisTest()

	cmd_disable := mock.Command("HMSET", "MIRROR_m1", "enabled", false).Expect("ok")
	DisableMirror(conn, "m1")

	if mock.Stats(cmd_disable) != 1 {
		t.Fatalf("Mirror not enabled")
	}

	mock.Command("HMSET", "MIRROR_m1", "enabled", false).ExpectError(redis.Error("blah"))
	if DisableMirror(conn, "m1") == nil {
		t.Fatalf("Error expected")
	}
}
Exemplo n.º 4
0
func TestPoolBorrowCheck(t *testing.T) {
	d := poolDialer{t: t}
	p := &redis.Pool{
		MaxIdle:      2,
		Dial:         d.dial,
		TestOnBorrow: func(redis.Conn, time.Time) error { return redis.Error("BLAH") },
	}
	defer p.Close()

	for i := 0; i < 10; i++ {
		c := p.Get()
		c.Do("PING")
		c.Close()
	}
	d.check("1", p, 10, 1)
}
Exemplo n.º 5
0
		if !reflect.DeepEqual(tt.dest, dest.Elem().Interface()) {
			t.Errorf("Scan(%v) returned %v, want %v", tt, dest.Elem().Interface(), tt.dest)
		}
	}
}

var scanConversionErrorTests = []struct {
	src  interface{}
	dest interface{}
}{
	{[]byte("1234"), byte(0)},
	{int64(1234), byte(0)},
	{[]byte("-1"), byte(0)},
	{int64(-1), byte(0)},
	{[]byte("junk"), false},
	{redis.Error("blah"), false},
}

func TestScanConversionError(t *testing.T) {
	for _, tt := range scanConversionErrorTests {
		values := []interface{}{tt.src}
		dest := reflect.New(reflect.TypeOf(tt.dest))
		values, err := redis.Scan(values, dest.Interface())
		if err == nil {
			t.Errorf("Scan(%v) did not return error", tt)
		}
	}
}

func ExampleScan() {
	c, err := dial()