From 21a8c2fc885caf6fa8cc8b4d908186f5ddc22916 Mon Sep 17 00:00:00 2001 From: Michael Kuc Date: Tue, 22 Aug 2023 14:44:20 +0100 Subject: [PATCH] feat: Add select command. Adds expectations for the SELECT command, which changes the connection's currently selected DB. --- commands_test.go | 10 ++++++++++ expect.go | 1 + mock.go | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/commands_test.go b/commands_test.go index b237bdd..6332f1b 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2469,6 +2469,16 @@ var _ = Describe("Commands", func() { }) }) + if c, ok := client.(*redis.Client); ok { + It("Save", func() { + operationStatusCmd(clientMock, func() *ExpectedStatus { + return clientMock.ExpectSelect(1) + }, func() *redis.StatusCmd { + return c.Conn().Select(ctx, 1) + }) + }) + } + It("Shutdown", func() { //no test }) diff --git a/expect.go b/expect.go index 249b7fb..abaf250 100644 --- a/expect.go +++ b/expect.go @@ -285,6 +285,7 @@ type baseMock interface { ExpectInfo(section ...string) *ExpectedString ExpectLastSave() *ExpectedInt ExpectSave() *ExpectedStatus + ExpectSelect(index int) *ExpectedStatus ExpectShutdown() *ExpectedStatus ExpectShutdownSave() *ExpectedStatus ExpectShutdownNoSave() *ExpectedStatus diff --git a/mock.go b/mock.go index c8c28b9..7e4131d 100644 --- a/mock.go +++ b/mock.go @@ -2187,6 +2187,13 @@ func (m *mock) ExpectSave() *ExpectedStatus { return e } +func (m *mock) ExpectSelect(index int) *ExpectedStatus { + e := &ExpectedStatus{} + e.cmd = redis.NewStatusCmd(m.ctx, "select", index) + m.pushExpect(e) + return e +} + func (m *mock) ExpectShutdown() *ExpectedStatus { e := &ExpectedStatus{} e.cmd = m.factory.Shutdown(m.ctx)