2
0

datatype.tcl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. set testmodule [file normalize tests/modules/datatype.so]
  2. start_server {tags {"modules"}} {
  3. r module load $testmodule
  4. test {DataType: Test module is sane, GET/SET work.} {
  5. r datatype.set dtkey 100 stringval
  6. assert {[r datatype.get dtkey] eq {100 stringval}}
  7. }
  8. test {DataType: RM_SaveDataTypeToString(), RM_LoadDataTypeFromStringEncver() work} {
  9. r datatype.set dtkey -1111 MyString
  10. set encoded [r datatype.dump dtkey]
  11. assert {[r datatype.restore dtkeycopy $encoded 4] eq {4}}
  12. assert {[r datatype.get dtkeycopy] eq {-1111 MyString}}
  13. }
  14. test {DataType: Handle truncated RM_LoadDataTypeFromStringEncver()} {
  15. r datatype.set dtkey -1111 MyString
  16. set encoded [r datatype.dump dtkey]
  17. set truncated [string range $encoded 0 end-1]
  18. catch {r datatype.restore dtkeycopy $truncated 4} e
  19. set e
  20. } {*Invalid*}
  21. test {DataType: ModuleTypeReplaceValue() happy path works} {
  22. r datatype.set key-a 1 AAA
  23. r datatype.set key-b 2 BBB
  24. assert {[r datatype.swap key-a key-b] eq {OK}}
  25. assert {[r datatype.get key-a] eq {2 BBB}}
  26. assert {[r datatype.get key-b] eq {1 AAA}}
  27. }
  28. test {DataType: ModuleTypeReplaceValue() fails on non-module keys} {
  29. r datatype.set key-a 1 AAA
  30. r set key-b RedisString
  31. catch {r datatype.swap key-a key-b} e
  32. set e
  33. } {*ERR*}
  34. test {DataType: Copy command works for modules} {
  35. # Test failed copies
  36. r datatype.set answer-to-universe 42 AAA
  37. catch {r copy answer-to-universe answer2} e
  38. assert_match {*module key failed to copy*} $e
  39. # Our module's data type copy function copies the int value as-is
  40. # but appends /<from-key>/<to-key> to the string value so we can
  41. # track passed arguments.
  42. r datatype.set sourcekey 1234 AAA
  43. r copy sourcekey targetkey
  44. r datatype.get targetkey
  45. } {1234 AAA/sourcekey/targetkey}
  46. }