aboutsummaryrefslogtreecommitdiff
path: root/examples/redis-unstable/tests/unit/moduleapi/keyspecs.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'examples/redis-unstable/tests/unit/moduleapi/keyspecs.tcl')
-rw-r--r--examples/redis-unstable/tests/unit/moduleapi/keyspecs.tcl160
1 files changed, 0 insertions, 160 deletions
diff --git a/examples/redis-unstable/tests/unit/moduleapi/keyspecs.tcl b/examples/redis-unstable/tests/unit/moduleapi/keyspecs.tcl
deleted file mode 100644
index 3b98b80..0000000
--- a/examples/redis-unstable/tests/unit/moduleapi/keyspecs.tcl
+++ /dev/null
@@ -1,160 +0,0 @@
1set testmodule [file normalize tests/modules/keyspecs.so]
2
3start_server {tags {"modules external:skip"}} {
4 r module load $testmodule
5
6 test "Module key specs: No spec, only legacy triple" {
7 set reply [lindex [r command info kspec.none] 0]
8 # Verify (first, last, step) and not movablekeys
9 assert_equal [lindex $reply 2] {module}
10 assert_equal [lindex $reply 3] 1
11 assert_equal [lindex $reply 4] -1
12 assert_equal [lindex $reply 5] 2
13 # Verify key-spec auto-generated from the legacy triple
14 set keyspecs [lindex $reply 8]
15 assert_equal [llength $keyspecs] 1
16 assert_equal [lindex $keyspecs 0] {flags {RW access update} begin_search {type index spec {index 1}} find_keys {type range spec {lastkey -1 keystep 2 limit 0}}}
17 assert_equal [r command getkeys kspec.none key1 val1 key2 val2] {key1 key2}
18 }
19
20 test "Module key specs: No spec, only legacy triple with getkeys-api" {
21 set reply [lindex [r command info kspec.nonewithgetkeys] 0]
22 # Verify (first, last, step) and movablekeys
23 assert_equal [lindex $reply 2] {module movablekeys}
24 assert_equal [lindex $reply 3] 1
25 assert_equal [lindex $reply 4] -1
26 assert_equal [lindex $reply 5] 2
27 # Verify key-spec auto-generated from the legacy triple
28 set keyspecs [lindex $reply 8]
29 assert_equal [llength $keyspecs] 1
30 assert_equal [lindex $keyspecs 0] {flags {RW access update variable_flags} begin_search {type index spec {index 1}} find_keys {type range spec {lastkey -1 keystep 2 limit 0}}}
31 assert_equal [r command getkeys kspec.nonewithgetkeys key1 val1 key2 val2] {key1 key2}
32 }
33
34 test "Module key specs: Two ranges" {
35 set reply [lindex [r command info kspec.tworanges] 0]
36 # Verify (first, last, step) and not movablekeys
37 assert_equal [lindex $reply 2] {module}
38 assert_equal [lindex $reply 3] 1
39 assert_equal [lindex $reply 4] 2
40 assert_equal [lindex $reply 5] 1
41 # Verify key-specs
42 set keyspecs [lindex $reply 8]
43 assert_equal [lindex $keyspecs 0] {flags {RO access} begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
44 assert_equal [lindex $keyspecs 1] {flags {RW update} begin_search {type index spec {index 2}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
45 assert_equal [r command getkeys kspec.tworanges foo bar baz quux] {foo bar}
46 }
47
48 test "Module key specs: Two ranges with gap" {
49 set reply [lindex [r command info kspec.tworangeswithgap] 0]
50 # Verify (first, last, step) and movablekeys
51 assert_equal [lindex $reply 2] {module movablekeys}
52 assert_equal [lindex $reply 3] 1
53 assert_equal [lindex $reply 4] 1
54 assert_equal [lindex $reply 5] 1
55 # Verify key-specs
56 set keyspecs [lindex $reply 8]
57 assert_equal [lindex $keyspecs 0] {flags {RO access} begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
58 assert_equal [lindex $keyspecs 1] {flags {RW update} begin_search {type index spec {index 3}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
59 assert_equal [r command getkeys kspec.tworangeswithgap foo bar baz quux] {foo baz}
60 }
61
62 test "Module key specs: Keyword-only spec clears the legacy triple" {
63 set reply [lindex [r command info kspec.keyword] 0]
64 # Verify (first, last, step) and movablekeys
65 assert_equal [lindex $reply 2] {module movablekeys}
66 assert_equal [lindex $reply 3] 0
67 assert_equal [lindex $reply 4] 0
68 assert_equal [lindex $reply 5] 0
69 # Verify key-specs
70 set keyspecs [lindex $reply 8]
71 assert_equal [lindex $keyspecs 0] {flags {RO access} begin_search {type keyword spec {keyword KEYS startfrom 1}} find_keys {type range spec {lastkey -1 keystep 1 limit 0}}}
72 assert_equal [r command getkeys kspec.keyword foo KEYS bar baz] {bar baz}
73 }
74
75 test "Module key specs: Complex specs, case 1" {
76 set reply [lindex [r command info kspec.complex1] 0]
77 # Verify (first, last, step) and movablekeys
78 assert_equal [lindex $reply 2] {module movablekeys}
79 assert_equal [lindex $reply 3] 1
80 assert_equal [lindex $reply 4] 1
81 assert_equal [lindex $reply 5] 1
82 # Verify key-specs
83 set keyspecs [lindex $reply 8]
84 assert_equal [lindex $keyspecs 0] {flags RO begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
85 assert_equal [lindex $keyspecs 1] {flags {RW update} begin_search {type keyword spec {keyword STORE startfrom 2}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
86 assert_equal [lindex $keyspecs 2] {flags {RO access} begin_search {type keyword spec {keyword KEYS startfrom 2}} find_keys {type keynum spec {keynumidx 0 firstkey 1 keystep 1}}}
87 assert_equal [r command getkeys kspec.complex1 foo dummy KEYS 1 bar baz STORE quux] {foo quux bar}
88 }
89
90 test "Module key specs: Complex specs, case 2" {
91 set reply [lindex [r command info kspec.complex2] 0]
92 # Verify (first, last, step) and movablekeys
93 assert_equal [lindex $reply 2] {module movablekeys}
94 assert_equal [lindex $reply 3] 1
95 assert_equal [lindex $reply 4] 2
96 assert_equal [lindex $reply 5] 1
97 # Verify key-specs
98 set keyspecs [lindex $reply 8]
99 assert_equal [lindex $keyspecs 0] {flags {RW update} begin_search {type keyword spec {keyword STORE startfrom 5}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
100 assert_equal [lindex $keyspecs 1] {flags {RO access} begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
101 assert_equal [lindex $keyspecs 2] {flags {RO access} begin_search {type index spec {index 2}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
102 assert_equal [lindex $keyspecs 3] {flags {RW update} begin_search {type index spec {index 3}} find_keys {type keynum spec {keynumidx 0 firstkey 1 keystep 1}}}
103 assert_equal [lindex $keyspecs 4] {flags {RW update} begin_search {type keyword spec {keyword MOREKEYS startfrom 5}} find_keys {type range spec {lastkey -1 keystep 1 limit 0}}}
104 assert_equal [r command getkeys kspec.complex2 foo bar 2 baz quux banana STORE dst dummy MOREKEYS hey ho] {dst foo bar baz quux hey ho}
105 }
106
107 test "Module command list filtering" {
108 ;# Note: we piggyback this tcl file to test the general functionality of command list filtering
109 set reply [r command list filterby module keyspecs]
110 assert_equal [lsort $reply] {kspec.complex1 kspec.complex2 kspec.keyword kspec.none kspec.nonewithgetkeys kspec.tworanges kspec.tworangeswithgap}
111 assert_equal [r command getkeys kspec.complex2 foo bar 2 baz quux banana STORE dst dummy MOREKEYS hey ho] {dst foo bar baz quux hey ho}
112 }
113
114 test {COMMAND GETKEYSANDFLAGS correctly reports module key-spec without flags} {
115 r command getkeysandflags kspec.none key1 val1 key2 val2
116 } {{key1 {RW access update}} {key2 {RW access update}}}
117
118 test {COMMAND GETKEYSANDFLAGS correctly reports module key-spec with flags} {
119 r command getkeysandflags kspec.nonewithgetkeys key1 val1 key2 val2
120 } {{key1 {RO access}} {key2 {RO access}}}
121
122 test {COMMAND GETKEYSANDFLAGS correctly reports module key-spec flags} {
123 r command getkeysandflags kspec.keyword keys key1 key2 key3
124 } {{key1 {RO access}} {key2 {RO access}} {key3 {RO access}}}
125
126 # user that can only read from "read" keys, write to "write" keys, and read+write to "RW" keys
127 r ACL setuser testuser +@all %R~read* %W~write* %RW~rw*
128
129 test "Module key specs: No spec, only legacy triple - ACL" {
130 # legacy triple didn't provide flags, so they require both read and write
131 assert_equal "OK" [r ACL DRYRUN testuser kspec.none rw val1]
132 assert_match {*has no permissions to access the 'read' key*} [r ACL DRYRUN testuser kspec.none read val1]
133 assert_match {*has no permissions to access the 'write' key*} [r ACL DRYRUN testuser kspec.none write val1]
134 }
135
136 test "Module key specs: tworanges - ACL" {
137 assert_equal "OK" [r ACL DRYRUN testuser kspec.tworanges read write]
138 assert_equal "OK" [r ACL DRYRUN testuser kspec.tworanges rw rw]
139 assert_match {*has no permissions to access the 'read' key*} [r ACL DRYRUN testuser kspec.tworanges rw read]
140 assert_match {*has no permissions to access the 'write' key*} [r ACL DRYRUN testuser kspec.tworanges write rw]
141 }
142
143 foreach cmd {kspec.none kspec.tworanges} {
144 test "$cmd command will not be marked with movablekeys" {
145 set info [lindex [r command info $cmd] 0]
146 assert_no_match {*movablekeys*} [lindex $info 2]
147 }
148 }
149
150 foreach cmd {kspec.keyword kspec.complex1 kspec.complex2 kspec.nonewithgetkeys} {
151 test "$cmd command is marked with movablekeys" {
152 set info [lindex [r command info $cmd] 0]
153 assert_match {*movablekeys*} [lindex $info 2]
154 }
155 }
156
157 test "Unload the module - keyspecs" {
158 assert_equal {OK} [r module unload keyspecs]
159 }
160}