Skip to content

Commit b1be11b

Browse files
Expanding test and fixing reading of response for AclLog
1 parent dba1eaf commit b1be11b

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

command.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5116,11 +5116,11 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error {
51165116
for i := 0; i < n; i++ {
51175117
cmd.val[i] = &ACLLogEntry{}
51185118
entry := cmd.val[i]
5119-
respLen, err := rd.ReadArrayLen()
5119+
respLen, err := rd.ReadMapLen()
51205120
if err != nil {
51215121
return err
51225122
}
5123-
for j := 0; j < respLen/2; j++ {
5123+
for j := 0; j < respLen; j++ {
51245124
key, err := rd.ReadString()
51255125
if err != nil {
51265126
return err

commands_test.go

+21-5
Original file line numberDiff line numberDiff line change
@@ -1988,22 +1988,38 @@ var _ = Describe("Commands", func() {
19881988

19891989
It("should ACL LOG", func() {
19901990

1991+
err := client.Do(ctx, "acl", "setuser", "test", ">test", "on", "allkeys", "+get").Err()
1992+
Expect(err).NotTo(HaveOccurred())
1993+
1994+
clientAcl := redis.NewClient(redisOptions())
1995+
clientAcl.Options().Username = "test"
1996+
clientAcl.Options().Password = "test"
1997+
clientAcl.Options().DB = 0
1998+
_ = clientAcl.Set(ctx, "mystring", "foo", 0).Err()
1999+
_ = clientAcl.HSet(ctx, "myhash", "foo", "bar").Err()
2000+
_ = clientAcl.SAdd(ctx, "myset", "foo", "bar").Err()
2001+
19912002
logEntries, err := client.ACLLog(ctx, 10).Result()
19922003
Expect(err).NotTo(HaveOccurred())
1993-
Expect(logEntries).NotTo(BeNil())
2004+
Expect(len(logEntries)).To(Equal(3))
19942005

19952006
for _, entry := range logEntries {
1996-
Expect(entry.Count).To(BeNumerically(">=", 0))
1997-
Expect(entry.Reason).NotTo(BeEmpty())
1998-
Expect(entry.Context).NotTo(BeEmpty())
2007+
Expect(entry.Count).To(BeNumerically("==", 1))
2008+
Expect(entry.Reason).To(Equal("command"))
2009+
Expect(entry.Context).To(Equal("toplevel"))
19992010
Expect(entry.Object).NotTo(BeEmpty())
2000-
Expect(entry.Username).NotTo(BeEmpty())
2011+
Expect(entry.Username).To(Equal("test"))
20012012
Expect(entry.AgeSeconds).To(BeNumerically(">=", 0))
20022013
Expect(entry.ClientInfo).NotTo(BeNil())
20032014
Expect(entry.EntryID).To(BeNumerically(">=", 0))
20042015
Expect(entry.TimestampCreated).To(BeNumerically(">=", 0))
20052016
Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0))
20062017
}
2018+
2019+
limitedLogEntries, err := client.ACLLog(ctx, 2).Result()
2020+
Expect(err).NotTo(HaveOccurred())
2021+
Expect(len(limitedLogEntries)).To(Equal(2))
2022+
20072023
})
20082024

20092025
It("should ACL LOG RESET", func() {

0 commit comments

Comments
 (0)