1
0

reply.tcl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. set testmodule [file normalize tests/modules/reply.so]
  2. # test all with hello 2/3
  3. start_server {tags {"modules"}} {
  4. r module load $testmodule
  5. for {proto=2; proto<=3; incr proto} {
  6. r hello $proto
  7. test {RM_ReplyWithString: an string reply} {
  8. # RedisString
  9. set string [r rw.string "Redis"]
  10. assert_equal "Redis" $string
  11. # C string
  12. set string [r rw.cstring]
  13. assert_equal "A simple string" $string
  14. }
  15. test {RM_ReplyWithInt: an integer reply} {
  16. assert_equal 42 [r rw.int 42]
  17. }
  18. test {RM_ReplyWithDouble: a float reply} {
  19. assert_equal 3.141 [r rw.double 3.141]
  20. }
  21. test {RM_ReplyWithLongDouble: a float reply} {
  22. assert_equal 3.141 [r rw.longdouble 3.141]
  23. }
  24. test {RM_ReplyWithVerbatimString: a string reply} {
  25. assert_equal "bla\nbla\nbla" [r rw.verbatim "bla\nbla\nbla"]
  26. }
  27. test {RM_ReplyWithArray: an array reply} {
  28. assert_equal {0 1 2 3 4} [r rw.array 5]
  29. }
  30. test {RM_ReplyWithMap: an map reply} {
  31. set res [r rw.map 3]
  32. if {$proto == 2} {
  33. assert_equal {0 0.0 1 1.5 2 3.0} $res
  34. } else {
  35. assert_equal [dict create 0 0.0 1 1.5 2 3.0] $res
  36. }
  37. }
  38. test {RM_ReplyWithSet: an set reply} {
  39. assert_equal {0 1 2} [r rw.set 3]
  40. }
  41. test {RM_ReplyWithAttribute: an set reply} {
  42. set res [r rw.attribute 3]
  43. if {$proto == 2} {
  44. catch {r rw.error} e
  45. assert_match "Attributes aren't supported by RESP 2" $e
  46. } else {
  47. assert_equal [dict create 0 0.0 1 1.5 2 3.0] $res
  48. }
  49. assert_equal "OK" $res
  50. }
  51. test {RM_ReplyWithBool: a boolean reply} {
  52. assert_equal {0 1} [r rw.bool]
  53. }
  54. test {RM_ReplyWithNull: a NULL reply} {
  55. assert_equal {} [r rw.null]
  56. }
  57. test {RM_ReplyWithError: an error reply} {
  58. catch {r rw.error} e
  59. assert_match "An error" $e
  60. }
  61. }
  62. }