Annotate

spec/util_datamanager_spec.lua @ 13262:9a86e7cbdd79

mod_storage_internal: Fix fast trimming of archive with exactly one item This method would previously never delete the first (and only) item since it works out which item should become the first item after the trim operation, which doesn't make sense when all should be removed. This also works as an optimization for when all the last item should be trimmed, thus items should be removed.
author Kim Alvefur <zash@zash.se>
date Sun, 24 Sep 2023 13:41:54 +0200
parent 11370:7c2ef5a1ec9c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11370
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 describe("util.datamanager", function()
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local dm;
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 setup(function()
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 dm = require "util.datamanager";
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 dm.set_data_path("./data");
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 end);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 describe("keyvalue", function()
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local data = {hello = "world"};
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local ok, err = dm.store("keyval-user", "datamanager.test", "testdata", data);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 assert.truthy(ok, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local read, err = dm.load("keyval-user", "datamanager.test", "testdata")
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 assert.same(data, read, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 local ok, err = dm.store("keyval-user", "datamanager.test", "testdata", nil);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 assert.truthy(ok, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 local read, err = dm.load("keyval-user", "datamanager.test", "testdata")
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 assert.is_nil(read, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end)
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 describe("lists", function()
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 local ok, err = dm.list_store("list-user", "datamanager.test", "testdata", {});
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 assert.truthy(ok, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 local nothing, err = dm.list_load("list-user", "datamanager.test", "testdata");
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 assert.is_nil(nothing, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 assert.is_nil(err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 local ok, err = dm.list_append("list-user", "datamanager.test", "testdata", {id = 1});
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 assert.truthy(ok, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 local ok, err = dm.list_append("list-user", "datamanager.test", "testdata", {id = 2});
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 assert.truthy(ok, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 local ok, err = dm.list_append("list-user", "datamanager.test", "testdata", {id = 3});
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 assert.truthy(ok, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 local list, err = dm.list_load("list-user", "datamanager.test", "testdata");
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 assert.same(list, {{id = 1}; {id = 2}; {id = 3}}, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 local ok, err = dm.list_store("list-user", "datamanager.test", "testdata", {});
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 assert.truthy(ok, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 do
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 local nothing, err = dm.list_load("list-user", "datamanager.test", "testdata");
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 assert.is_nil(nothing, err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 assert.is_nil(err);
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 end
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 end)
7c2ef5a1ec9c util.datamanager: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 end)