diff options
author | Kim Alvefur <zash@zash.se> | 2021-02-09 23:25:30 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-02-09 23:25:30 +0100 |
commit | eec6e6d38e78e4e912fff102c448e679b1cf2de6 (patch) | |
tree | 363b96f223f6be7a382b0c1a472600f8e4ccf29d | |
parent | f0069378bd6e58d9439e0156a3c216cbd2bd9360 (diff) | |
download | prosody-eec6e6d38e78e4e912fff102c448e679b1cf2de6.tar.gz prosody-eec6e6d38e78e4e912fff102c448e679b1cf2de6.zip |
util.datamanager: Add basic testsorigin/vault/master
Test all the things! Somewhat covered by the storagemanager tests, but
we don't currently don't have that automated as it needs SQL engines.
-rw-r--r-- | spec/util_datamanager_spec.lua | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/util_datamanager_spec.lua b/spec/util_datamanager_spec.lua new file mode 100644 index 00000000..d46590e8 --- /dev/null +++ b/spec/util_datamanager_spec.lua @@ -0,0 +1,76 @@ +describe("util.datamanager", function() + local dm; + setup(function() + dm = require "util.datamanager"; + dm.set_data_path("./data"); + end); + + describe("keyvalue", function() + local data = {hello = "world"}; + + do + local ok, err = dm.store("keyval-user", "datamanager.test", "testdata", data); + assert.truthy(ok, err); + end + + do + local read, err = dm.load("keyval-user", "datamanager.test", "testdata") + assert.same(data, read, err); + end + + do + local ok, err = dm.store("keyval-user", "datamanager.test", "testdata", nil); + assert.truthy(ok, err); + end + + do + local read, err = dm.load("keyval-user", "datamanager.test", "testdata") + assert.is_nil(read, err); + end + end) + + describe("lists", function() + do + local ok, err = dm.list_store("list-user", "datamanager.test", "testdata", {}); + assert.truthy(ok, err); + end + + do + local nothing, err = dm.list_load("list-user", "datamanager.test", "testdata"); + assert.is_nil(nothing, err); + assert.is_nil(err); + end + + do + local ok, err = dm.list_append("list-user", "datamanager.test", "testdata", {id = 1}); + assert.truthy(ok, err); + end + + do + local ok, err = dm.list_append("list-user", "datamanager.test", "testdata", {id = 2}); + assert.truthy(ok, err); + end + + do + local ok, err = dm.list_append("list-user", "datamanager.test", "testdata", {id = 3}); + assert.truthy(ok, err); + end + + do + local list, err = dm.list_load("list-user", "datamanager.test", "testdata"); + assert.same(list, {{id = 1}; {id = 2}; {id = 3}}, err); + end + + do + local ok, err = dm.list_store("list-user", "datamanager.test", "testdata", {}); + assert.truthy(ok, err); + end + + do + local nothing, err = dm.list_load("list-user", "datamanager.test", "testdata"); + assert.is_nil(nothing, err); + assert.is_nil(err); + end + + end) +end) |