Exemplo n.º 1
0
		})
	})

	Describe("#Incr", func() {
		It("calls INCR on the redis connection", func() {
			var incrCalled bool
			fakeConnection.RespondToDo(func(command string, args ...interface{}) (interface{}, error) {
				incrCalled = true
				Expect(command).To(Equal("INCR"))
				Expect(args[0]).To(HaveLen(1))
				Expect(args[0].([]interface{})[0]).To(Equal("my key"))

				return int64(42), nil
			})

			val, err := commander.Incr("my key")
			Expect(err).To(BeNil())
			Expect(incrCalled).To(BeTrue())
			Expect(val).To(Equal(42))
		})

		It("returns the redis error", func() {
			fakeConnection.RespondToDo(func(string, ...interface{}) (interface{}, error) {
				return nil, errors.New("incr error")
			})

			_, err := commander.Incr("my key")
			Expect(err.Error()).To(Equal("incr error"))
		})
	})