mirror of
https://github.com/fluencelabs/redis
synced 2025-03-17 16:10:50 +00:00
Tests for redis-cli in non-interactive mode
Minor change in redis-cli output for the (multi-)bulk response but this will be fixed in the next commit.
This commit is contained in:
parent
0439d792c4
commit
07242c0ccf
@ -134,7 +134,7 @@ static void printStringRepr(char *s, int len) {
|
||||
}
|
||||
s++;
|
||||
}
|
||||
printf("\"\n");
|
||||
printf("\"");
|
||||
}
|
||||
|
||||
static int cliReadBulkReply(int fd) {
|
||||
@ -152,7 +152,7 @@ static int cliReadBulkReply(int fd) {
|
||||
reply = zmalloc(bulklen);
|
||||
anetRead(fd,reply,bulklen);
|
||||
anetRead(fd,crlf,2);
|
||||
if (config.raw_output || !config.interactive) {
|
||||
if (config.raw_output) {
|
||||
if (bulklen && fwrite(reply,bulklen,1,stdout) == 0) {
|
||||
zfree(reply);
|
||||
return 1;
|
||||
@ -161,6 +161,7 @@ static int cliReadBulkReply(int fd) {
|
||||
/* If you are producing output for the standard output we want
|
||||
* a more interesting output with quoted characters and so forth */
|
||||
printStringRepr(reply,bulklen);
|
||||
printf("\n");
|
||||
}
|
||||
zfree(reply);
|
||||
return 0;
|
||||
|
@ -41,6 +41,19 @@ start_server {tags {"cli"}} {
|
||||
close_cli $fd
|
||||
}
|
||||
|
||||
proc run_cli {args} {
|
||||
set fd [open [format "|src/redis-cli -p %d -n 9 $args" [srv port]] "r"]
|
||||
fconfigure $fd -buffering none
|
||||
fconfigure $fd -translation binary
|
||||
set resp [read $fd 1048576]
|
||||
close $fd
|
||||
set _ $resp
|
||||
}
|
||||
|
||||
proc test_noninteractive_cli {name code} {
|
||||
test "Non-interactive CLI: $name" $code
|
||||
}
|
||||
|
||||
test_interactive_cli "INFO response should be printed raw" {
|
||||
set lines [split [run_command $fd info] "\n"]
|
||||
foreach line $lines {
|
||||
@ -85,4 +98,26 @@ start_server {tags {"cli"}} {
|
||||
assert_equal "OK" [run_command $fd "set key\"\" bar"]
|
||||
assert_equal "bar" [r get key]
|
||||
}
|
||||
|
||||
test_noninteractive_cli "Status reply" {
|
||||
assert_equal "OK\n" [run_cli set key bar]
|
||||
assert_equal "bar" [r get key]
|
||||
}
|
||||
|
||||
test_noninteractive_cli "Integer reply" {
|
||||
r del counter
|
||||
assert_equal "(integer) 1\n" [run_cli incr counter]
|
||||
}
|
||||
|
||||
test_noninteractive_cli "Bulk reply" {
|
||||
r set key "tab\tnewline\n"
|
||||
assert_equal "\"tab\\tnewline\\n\"\n" [run_cli get key]
|
||||
}
|
||||
|
||||
test_noninteractive_cli "Multi-bulk reply" {
|
||||
r del list
|
||||
r rpush list foo
|
||||
r rpush list bar
|
||||
assert_equal "1. \"foo\"\n2. \"bar\"\n" [run_cli lrange list 0 -1]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user