Comparison

spec/core_storagemanager_spec.lua @ 10679:b50b1eae711c

storagemanager: Add support for :find_key() and :delete_key() to map store shim
author Matthew Wild <mwild1@gmail.com>
date Wed, 11 Mar 2020 16:29:57 +0000
parent 10678:c9251d74a112
child 10680:19692fc5c106
comparison
equal deleted inserted replaced
10678:c9251d74a112 10679:b50b1eae711c
60 end 60 end
61 assert(hm.activate(test_host, {})); 61 assert(hm.activate(test_host, {}));
62 sm.initialize_host(test_host); 62 sm.initialize_host(test_host);
63 assert(mm.load(test_host, "storage_"..backend_config.storage)); 63 assert(mm.load(test_host, "storage_"..backend_config.storage));
64 64
65 local sql_it = backend_config.sql and it or pending;
66
67
68 describe("key-value stores", function () 65 describe("key-value stores", function ()
69 -- These tests rely on being executed in order, disable any order 66 -- These tests rely on being executed in order, disable any order
70 -- randomization for this block 67 -- randomization for this block
71 randomize(false); 68 randomize(false);
72 69
114 111
115 it("may get a specific key for a user", function () 112 it("may get a specific key for a user", function ()
116 assert.equal("bar", store:get("user9999", "foo")); 113 assert.equal("bar", store:get("user9999", "foo"));
117 end); 114 end);
118 115
119 sql_it("may find all users with a specific key", function () 116 it("may find all users with a specific key", function ()
120 assert.is_function(store.find_key); 117 assert.is_function(store.find_key);
121 assert(store:set("user9999b", "bar", "bar")); 118 assert(store:set("user9999b", "bar", "bar"));
122 assert(store:set("user9999c", "foo", "blah")); 119 assert(store:set("user9999c", "foo", "blah"));
123 local ret, err = store:find_key("foo"); 120 local ret, err = store:find_key("foo");
124 assert.is_nil(err); 121 assert.is_nil(err);
125 assert.same({ user9999 = "bar", user9999c = "blah" }, ret); 122 assert.same({ user9999 = "bar", user9999c = "blah" }, ret);
126 end); 123 end);
127 124
128 sql_it("rejects empty or non-string keys to find_key", function () 125 it("rejects empty or non-string keys to find_key", function ()
129 assert.is_function(store.find_key); 126 assert.is_function(store.find_key);
130 do 127 do
131 local ret, err = store:find_key(""); 128 local ret, err = store:find_key("");
132 assert.is_nil(ret); 129 assert.is_nil(ret);
133 assert.is_not_nil(err); 130 assert.is_not_nil(err);
137 assert.is_nil(ret); 134 assert.is_nil(ret);
138 assert.is_not_nil(err); 135 assert.is_not_nil(err);
139 end 136 end
140 end); 137 end);
141 138
142 sql_it("rejects empty or non-string keys to delete_key", function () 139 it("rejects empty or non-string keys to delete_key", function ()
143 assert.is_function(store.delete_key); 140 assert.is_function(store.delete_key);
144 do 141 do
145 local ret, err = store:delete_key(""); 142 local ret, err = store:delete_key("");
146 assert.is_nil(ret); 143 assert.is_nil(ret);
147 assert.is_not_nil(err); 144 assert.is_not_nil(err);
151 assert.is_nil(ret); 148 assert.is_nil(ret);
152 assert.is_not_nil(err); 149 assert.is_not_nil(err);
153 end 150 end
154 end); 151 end);
155 152
156 sql_it("may delete all instances of a specific key", function () 153 it("may delete all instances of a specific key", function ()
157 assert.is_function(store.delete_key); 154 assert.is_function(store.delete_key);
158 assert(store:set("user9999b", "foo", "hello")); 155 assert(store:set("user9999b", "foo", "hello"));
159 156
160 assert(store:delete_key("bar")); 157 assert(store:delete_key("bar"));
161 -- Ensure key was deleted 158 -- Ensure key was deleted