]>
git.saurik.com Git - redis.git/blob - tests/integration/redis-cli.tcl
   1 start_server 
{tags 
{"cli"}} { 
   4         set fd 
[open [format "|src/redis-cli -p %d -n 9" [srv port
]] "r+"] 
   5         fconfigure $fd -buffering none
 
   6         fconfigure $fd -blocking false
 
   7         fconfigure $fd -translation binary 
   8         assert_equal 
"redis> " [read_cli 
$fd] 
  18         while {[string length 
$buf] == 0} { 
  19             # wait some time and try again 
  26     proc write_cli 
{fd buf
} { 
  31     proc run_command 
{fd cmd
} { 
  33         set lines 
[split [read_cli 
$fd] "\n"] 
  34         assert_equal 
"redis> " [lindex $lines end
] 
  35         join [lrange $lines 0 end-1
] "\n" 
  38     proc test_interactive_cli 
{name code
} { 
  40         test 
"Interactive CLI: $name" $code 
  44     proc run_nontty_cli 
{args
} { 
  45         set fd 
[open [format "|src/redis-cli -p %d -n 9 $args" [srv port
]] "r"] 
  46         fconfigure $fd -buffering none
 
  47         fconfigure $fd -translation binary 
  48         set resp 
[read $fd 1048576] 
  53     proc test_nontty_cli 
{name code
} { 
  54         test 
"Non-interactive non-TTY CLI: $name" $code 
  57     proc run_tty_cli 
{args
} { 
  59         set resp 
[run_nontty_cli 
{*}$args] 
  64     proc test_tty_cli 
{name code
} { 
  65         test 
"Non-interactive TTY CLI: $name" $code 
  68     test_interactive_cli 
"INFO response should be printed raw" { 
  69         set lines 
[split [run_command 
$fd info] "\n"] 
  71             assert 
[regexp {^
[a-z0-9_
]+:[a-z0-9_
]+} $line] 
  75     test_interactive_cli 
"Status reply" { 
  76         assert_equal 
"OK" [run_command 
$fd "set key foo"] 
  79     test_interactive_cli 
"Integer reply" { 
  80         assert_equal 
"(integer) 1" [run_command 
$fd "incr counter"] 
  83     test_interactive_cli 
"Bulk reply" { 
  85         assert_equal 
"\"foo\"" [run_command 
$fd "get key"] 
  88     test_interactive_cli 
"Multi-bulk reply" { 
  91         assert_equal 
"1. \"foo\"\n2. \"bar\"" [run_command 
$fd "lrange list 0 -1"] 
  94     test_interactive_cli 
"Parsing quotes" { 
  95         assert_equal 
"OK" [run_command 
$fd "set key \"bar\""] 
  96         assert_equal 
"bar" [r get key
] 
  97         assert_equal 
"OK" [run_command 
$fd "set key \" bar \""] 
  98         assert_equal 
" bar " [r get key
] 
  99         assert_equal 
"OK" [run_command 
$fd "set key \"\\\"bar\\\"\""] 
 100         assert_equal 
"\"bar\"" [r get key
] 
 101         assert_equal 
"OK" [run_command 
$fd "set key \"\tbar\t\""] 
 102         assert_equal 
"\tbar\t" [r get key
] 
 105         assert_equal 
"Invalid argument(s)" [run_command 
$fd "get \"\"key"] 
 106         assert_equal 
"Invalid argument(s)" [run_command 
$fd "get \"key\"x"] 
 108         # quotes after the argument are weird, but should be allowed 
 109         assert_equal 
"OK" [run_command 
$fd "set key\"\" bar"] 
 110         assert_equal 
"bar" [r get key
] 
 113     test_tty_cli 
"Status reply" { 
 114         assert_equal 
"OK\n" [run_tty_cli 
set key bar
] 
 115         assert_equal 
"bar" [r get key
] 
 118     test_tty_cli 
"Integer reply" { 
 120         assert_equal 
"(integer) 1\n" [run_tty_cli 
incr counter
] 
 123     test_tty_cli 
"Bulk reply" { 
 124         r 
set key 
"tab\tnewline\n" 
 125         assert_equal 
"\"tab\\tnewline\\n\"\n" [run_tty_cli get key
] 
 128     test_tty_cli 
"Multi-bulk reply" { 
 132         assert_equal 
"1. \"foo\"\n2. \"bar\"\n" [run_tty_cli 
lrange list 0 -1]