Software /
code /
prosody
Comparison
spec/util_datamanager_spec.lua @ 11370:7c2ef5a1ec9c
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 09 Feb 2021 23:25:30 +0100 |
comparison
equal
deleted
inserted
replaced
11369:87105a9a11df | 11370:7c2ef5a1ec9c |
---|---|
1 describe("util.datamanager", function() | |
2 local dm; | |
3 setup(function() | |
4 dm = require "util.datamanager"; | |
5 dm.set_data_path("./data"); | |
6 end); | |
7 | |
8 describe("keyvalue", function() | |
9 local data = {hello = "world"}; | |
10 | |
11 do | |
12 local ok, err = dm.store("keyval-user", "datamanager.test", "testdata", data); | |
13 assert.truthy(ok, err); | |
14 end | |
15 | |
16 do | |
17 local read, err = dm.load("keyval-user", "datamanager.test", "testdata") | |
18 assert.same(data, read, err); | |
19 end | |
20 | |
21 do | |
22 local ok, err = dm.store("keyval-user", "datamanager.test", "testdata", nil); | |
23 assert.truthy(ok, err); | |
24 end | |
25 | |
26 do | |
27 local read, err = dm.load("keyval-user", "datamanager.test", "testdata") | |
28 assert.is_nil(read, err); | |
29 end | |
30 end) | |
31 | |
32 describe("lists", function() | |
33 do | |
34 local ok, err = dm.list_store("list-user", "datamanager.test", "testdata", {}); | |
35 assert.truthy(ok, err); | |
36 end | |
37 | |
38 do | |
39 local nothing, err = dm.list_load("list-user", "datamanager.test", "testdata"); | |
40 assert.is_nil(nothing, err); | |
41 assert.is_nil(err); | |
42 end | |
43 | |
44 do | |
45 local ok, err = dm.list_append("list-user", "datamanager.test", "testdata", {id = 1}); | |
46 assert.truthy(ok, err); | |
47 end | |
48 | |
49 do | |
50 local ok, err = dm.list_append("list-user", "datamanager.test", "testdata", {id = 2}); | |
51 assert.truthy(ok, err); | |
52 end | |
53 | |
54 do | |
55 local ok, err = dm.list_append("list-user", "datamanager.test", "testdata", {id = 3}); | |
56 assert.truthy(ok, err); | |
57 end | |
58 | |
59 do | |
60 local list, err = dm.list_load("list-user", "datamanager.test", "testdata"); | |
61 assert.same(list, {{id = 1}; {id = 2}; {id = 3}}, err); | |
62 end | |
63 | |
64 do | |
65 local ok, err = dm.list_store("list-user", "datamanager.test", "testdata", {}); | |
66 assert.truthy(ok, err); | |
67 end | |
68 | |
69 do | |
70 local nothing, err = dm.list_load("list-user", "datamanager.test", "testdata"); | |
71 assert.is_nil(nothing, err); | |
72 assert.is_nil(err); | |
73 end | |
74 | |
75 end) | |
76 end) |