aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_datamanager_spec.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-02-09 23:25:30 +0100
committerKim Alvefur <zash@zash.se>2021-02-09 23:25:30 +0100
commitcb489d06e1c0e5764269d96388a4f9504676bd09 (patch)
tree363b96f223f6be7a382b0c1a472600f8e4ccf29d /spec/util_datamanager_spec.lua
parentac2d84a47bc9050038b24e87679861919926e77c (diff)
downloadprosody-cb489d06e1c0e5764269d96388a4f9504676bd09.tar.gz
prosody-cb489d06e1c0e5764269d96388a4f9504676bd09.zip
util.datamanager: Add basic tests
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.
Diffstat (limited to 'spec/util_datamanager_spec.lua')
-rw-r--r--spec/util_datamanager_spec.lua76
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)