Skip to content

Commit

Permalink
adding some tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Dec 9, 2024
1 parent 66655d8 commit 7630eba
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions tests/unit/introspection.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,86 @@ start_server {tags {"introspection"}} {
r client info
} {id=* addr=*:* laddr=*:* fd=* name=* age=* idle=* flags=N db=* sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=* argv-mem=* multi-mem=0 rbs=* rbp=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client|info user=* redir=-1 resp=* lib-name=* lib-ver=* tot-net-in=* tot-net-out=* tot-cmds=*}

test {CLIENT LIST with ADDR filter} {
set client_info [r client info]
regexp {addr=([^ ]+)} $client_info match myaddr
set cl [split [r client list addr $myaddr] "\r\n"]
regexp {addr=([^ ]+) .* cmd=([^ ]+)} [lindex $cl 0] _ actual_addr actual_cmd
assert_equal $myaddr $actual_addr
assert_equal "client|list" $actual_cmd
}

test {CLIENT LIST with LADDR filter} {
set client_info [r client info]
regexp {laddr=([^ ]+)} $client_info match myladdr
set cl [split [r client list laddr $myladdr] "\r\n"]

regexp {laddr=([^ ]+)} [lindex $cl 0] _ actual_laddr

assert_equal $myladdr $actual_laddr
}

test {CLIENT LIST with MAXAGE filter} {
set cl [split [r client list maxage 1000000] "\r\n"]

foreach line $cl {
regexp {age=([0-9]+)} $line _ age
assert {[expr {$age <= 1000000}]}
}
}

test {CLIENT LIST with TYPE filter} {
set cl [split [r client list type normal] "\r\n"]

foreach line $cl {
regexp {flags=([^ ]+)} $line _ flags
assert [regexp {.*N.*} $flags]
}
}

test {CLIENT LIST with USER filter} {
set client_info [r client info]
regexp {user=([^ ]+)} $client_info match myuser
set cl [split [r client list user $myuser] "\r\n"]

foreach line $cl {
regexp {user=([^ ]+)} $line _ actual_user
assert_equal $myuser $actual_user
}
}

test {CLIENT LIST with SKIPME filter} {
set cl [split [r client list skipme no] "\r\n"]

set found_self 0
foreach line $cl {
regexp {id=([0-9]+)} $line _ client_id
if {[expr {$client_id == [r client id]}]} {
set found_self 1
}
}

assert_equal $found_self 1
}

test {CLIENT LIST with illegal arguments} {
assert_error "ERR syntax error*" {r client list id 10 wrong_arg}

assert_error "ERR *greater than 0*" {r client list id str}
assert_error "ERR *greater than 0*" {r client list id -1}
assert_error "ERR *greater than 0*" {r client list id 0}

assert_error "ERR Unknown client type*" {r client list type wrong_type}

assert_error "ERR No such user*" {r client list user wrong_user}

assert_error "ERR syntax error*" {r client list skipme yes_or_no}

assert_error "ERR *not an integer or out of range*" {r client list maxage str}
assert_error "ERR *not an integer or out of range*" {r client list maxage 9999999999999999999}
assert_error "ERR *greater than 0*" {r client list maxage -1}
}

proc get_field_in_client_info {info field} {
set info [string trim $info]
foreach item [split $info " "] {
Expand Down

0 comments on commit 7630eba

Please sign in to comment.