From 7630ebaad525071734b7ef3e5414136f78ae61d1 Mon Sep 17 00:00:00 2001 From: Sarthak Aggarwal Date: Sun, 8 Dec 2024 16:58:09 -0800 Subject: [PATCH] adding some tests Signed-off-by: Sarthak Aggarwal --- tests/unit/introspection.tcl | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tests/unit/introspection.tcl b/tests/unit/introspection.tcl index bafc46d4b7..6311bafe4d 100644 --- a/tests/unit/introspection.tcl +++ b/tests/unit/introspection.tcl @@ -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 " "] {