Skip to content

Commit 5042035

Browse files
authored
Merge pull request #70 from monkey92t/new_cmd
feat: add SlusterShareds command
2 parents 0b85ee4 + 890f8f8 commit 5042035

File tree

6 files changed

+96
-3
lines changed

6 files changed

+96
-3
lines changed

commands_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,14 @@ var _ = Describe("Commands", func() {
26652665
})
26662666
})
26672667

2668+
It("ClusterShards", func() {
2669+
operationClusterShardsCmd(clientMock, func() *ExpectedClusterShards {
2670+
return clientMock.ExpectClusterShards()
2671+
}, func() *redis.ClusterShardsCmd {
2672+
return client.ClusterShards(ctx)
2673+
})
2674+
})
2675+
26682676
It("ClusterLinks", func() {
26692677
operationClusterLinksCmd(clientMock, func() *ExpectedClusterLinks {
26702678
return clientMock.ExpectClusterLinks()

expect.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ type baseMock interface {
314314
ExpectPubSubShardNumSub(channels ...string) *ExpectedMapStringInt
315315

316316
ExpectClusterSlots() *ExpectedClusterSlots
317+
ExpectClusterShards() *ExpectedClusterShards
317318
ExpectClusterLinks() *ExpectedClusterLinks
318319
ExpectClusterNodes() *ExpectedString
319320
ExpectClusterMeet(host, port string) *ExpectedStatus
@@ -1264,6 +1265,24 @@ func (cmd *ExpectedKeyFlags) inflow(c redis.Cmder) {
12641265

12651266
// ------------------------------------------------------------
12661267

1268+
type ExpectedClusterShards struct {
1269+
expectedBase
1270+
1271+
val []redis.ClusterShard
1272+
}
1273+
1274+
func (cmd *ExpectedClusterShards) SetVal(val []redis.ClusterShard) {
1275+
cmd.setVal = true
1276+
cmd.val = make([]redis.ClusterShard, len(val))
1277+
copy(cmd.val, val)
1278+
}
1279+
1280+
func (cmd *ExpectedClusterShards) inflow(c redis.Cmder) {
1281+
inflow(c, "val", cmd.val)
1282+
}
1283+
1284+
// ------------------------------------------------------------
1285+
12671286
type ExpectedError struct {
12681287
expectedBase
12691288
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/onsi/ginkgo v1.16.5
77
github.com/onsi/gomega v1.25.0
8-
github.com/redis/go-redis/v9 v9.0.3-0.20230328041954-42d730c1433b
8+
github.com/redis/go-redis/v9 v9.0.3-0.20230329134406-9aba95a74fa2
99
)
1010

1111
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
3838
github.com/onsi/gomega v1.25.0 h1:Vw7br2PCDYijJHSfBOWhov+8cAnUf8MfMaIOV323l6Y=
3939
github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
4040
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
41-
github.com/redis/go-redis/v9 v9.0.3-0.20230328041954-42d730c1433b h1:T3MMStZm8QZbklJHD4ksof/+U5AAqBbrqdfY/SdqQqM=
42-
github.com/redis/go-redis/v9 v9.0.3-0.20230328041954-42d730c1433b/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
41+
github.com/redis/go-redis/v9 v9.0.3-0.20230329134406-9aba95a74fa2 h1:3pTy4Z2GUTMRJBX2F+i7CvqyqQx10feStcprdzDzjFE=
42+
github.com/redis/go-redis/v9 v9.0.3-0.20230329134406-9aba95a74fa2/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
4343
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4444
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
4545
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

mock.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,6 +2369,13 @@ func (m *mock) ExpectClusterSlots() *ExpectedClusterSlots {
23692369
return e
23702370
}
23712371

2372+
func (m *mock) ExpectClusterShards() *ExpectedClusterShards {
2373+
e := &ExpectedClusterShards{}
2374+
e.cmd = m.factory.ClusterShards(m.ctx)
2375+
m.pushExpect(e)
2376+
return e
2377+
}
2378+
23722379
func (m *mock) ExpectClusterLinks() *ExpectedClusterLinks {
23732380
e := &ExpectedClusterLinks{}
23742381
e.cmd = m.factory.ClusterLinks(m.ctx)

mock_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,3 +1594,62 @@ func operationKeyFlagsCmd(base baseMock, expected func() *ExpectedKeyFlags, actu
15941594
Expect(err).NotTo(HaveOccurred())
15951595
Expect(val).To(Equal(kfs))
15961596
}
1597+
1598+
func operationClusterShardsCmd(base baseMock, expected func() *ExpectedClusterShards, actual func() *redis.ClusterShardsCmd) {
1599+
var (
1600+
setErr = errors.New("cluster shareds cmd error")
1601+
val []redis.ClusterShard
1602+
err error
1603+
)
1604+
1605+
base.ClearExpect()
1606+
expected().SetErr(setErr)
1607+
val, err = actual().Result()
1608+
Expect(err).To(Equal(setErr))
1609+
Expect(val).To(Equal([]redis.ClusterShard(nil)))
1610+
1611+
base.ClearExpect()
1612+
expected()
1613+
val, err = actual().Result()
1614+
Expect(err).To(HaveOccurred())
1615+
Expect(val).To(Equal([]redis.ClusterShard(nil)))
1616+
1617+
cs := []redis.ClusterShard{
1618+
{
1619+
Slots: []redis.SlotRange{
1620+
{Start: 0, End: 1999},
1621+
{Start: 4000, End: 5999},
1622+
},
1623+
Nodes: []redis.Node{
1624+
{
1625+
ID: "e10b7051d6bf2d5febd39a2be297bbaea6084111",
1626+
Endpoint: "127.0.0.1",
1627+
IP: "127.0.0.1",
1628+
Hostname: "host",
1629+
Port: 30001,
1630+
TLSPort: 1999,
1631+
Role: "master",
1632+
ReplicationOffset: 72156,
1633+
Health: "online",
1634+
},
1635+
{
1636+
ID: "fd20502fe1b32fc32c15b69b0a9537551f162f1f",
1637+
Endpoint: "127.0.0.1",
1638+
IP: "127.0.0.1",
1639+
Hostname: "host",
1640+
Port: 30002,
1641+
TLSPort: 1999,
1642+
Role: "replica",
1643+
ReplicationOffset: 72156,
1644+
Health: "online",
1645+
},
1646+
},
1647+
},
1648+
}
1649+
1650+
base.ClearExpect()
1651+
expected().SetVal(cs)
1652+
val, err = actual().Result()
1653+
Expect(err).NotTo(HaveOccurred())
1654+
Expect(val).To(Equal(cs))
1655+
}

0 commit comments

Comments
 (0)