Annotate

spec/core_storagemanager_spec.lua @ 9517:b1c6ede17592

util.promise: Add promise.try()
author Matthew Wild <mwild1@gmail.com>
date Thu, 18 Oct 2018 18:03:31 +0100
parent 9491:89e4cbd1a564
child 9536:4803ab9a5983
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local server = require "net.server_select";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 package.loaded["net.server"] = server;
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
9466
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
4 local st = require "util.stanza";
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
5
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local function mock_prosody()
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 _G.prosody = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 core_post_stanza = function () end;
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 events = require "util.events".new();
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 hosts = {};
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 paths = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 data = "./data";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 };
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 };
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local configs = {
9491
89e4cbd1a564 storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents: 9472
diff changeset
18 memory = {
89e4cbd1a564 storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents: 9472
diff changeset
19 storage = "memory";
89e4cbd1a564 storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents: 9472
diff changeset
20 };
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 internal = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 storage = "internal";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 };
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 sqlite = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 storage = "sql";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 sql = { driver = "SQLite3", database = "prosody-tests.sqlite" };
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 };
9452
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
28 mysql = {
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
29 storage = "sql";
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
30 sql = { driver = "MySQL", database = "prosody", username = "prosody", password = "secret", host = "localhost" };
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
31 };
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
32 postgres = {
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
33 storage = "sql";
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
34 sql = { driver = "PostgreSQL", database = "prosody", username = "prosody", password = "secret", host = "localhost" };
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
35 };
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 };
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 local test_host = "storage-unit-tests.invalid";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 describe("storagemanager", function ()
9452
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
41 for backend, backend_config in pairs(configs) do
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 local tagged_name = "#"..backend;
9452
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
43 if backend ~= backend_config.storage then
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9389
diff changeset
44 tagged_name = tagged_name.." #"..backend_config.storage;
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 insulate(tagged_name.." #storage backend", function ()
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 mock_prosody();
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 local config = require "core.configmanager";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 local sm = require "core.storagemanager";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 local hm = require "core.hostmanager";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 local mm = require "core.modulemanager";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 -- Simple check to ensure insulation is working correctly
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 assert.is_nil(config.get(test_host, "storage"));
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 for k, v in pairs(backend_config) do
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 config.set(test_host, k, v);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 assert(hm.activate(test_host, {}));
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 sm.initialize_host(test_host);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 assert(mm.load(test_host, "storage_"..backend_config.storage));
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63
9466
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
64 describe("key-value stores", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
65 -- These tests rely on being executed in order, disable any order
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
66 -- randomization for this block
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
67 randomize(false);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
68
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
69 local store;
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
70 it("may be opened", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
71 store = assert(sm.open(test_host, "test"));
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
72 end);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
73
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
74 local simple_data = { foo = "bar" };
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75
9466
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
76 it("may set data for a user", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
77 assert(store:set("user9999", simple_data));
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
78 end);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
79
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
80 it("may get data for a user", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
81 assert.same(simple_data, assert(store:get("user9999")));
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
82 end);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
83
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
84 it("may remove data for a user", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
85 assert(store:set("user9999", nil));
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
86 local ret, err = store:get("user9999");
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
87 assert.is_nil(ret);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
88 assert.is_nil(err);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
89 end);
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 end);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91
9466
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
92 describe("archive stores", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
93 randomize(false);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
94
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
95 local archive;
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
96 it("can be opened", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
97 archive = assert(sm.open(test_host, "test-archive", "archive"));
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
98 end);
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99
9466
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
100 local test_stanza = st.stanza("test", { xmlns = "urn:example:foo" })
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
101 :tag("foo"):up()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
102 :tag("foo"):up();
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
103 local test_time = 1539204123;
9470
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
104
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
105 local test_data = {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
106 { nil, test_stanza, test_time, "contact@example.com" };
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
107 { nil, test_stanza, test_time+1, "contact2@example.com" };
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
108 { nil, test_stanza, test_time+2, "contact2@example.com" };
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
109 { nil, test_stanza, test_time-1, "contact2@example.com" };
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
110 };
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
111
9466
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
112 it("can be added to", function ()
9470
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
113 for _, data_item in ipairs(test_data) do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
114 local ok = archive:append("user", unpack(data_item, 1, 4));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
115 assert.truthy(ok);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
116 end
9466
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
117 end);
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118
9470
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
119 describe("can be queried", function ()
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
120 it("for all items", function ()
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
121 local data, err = archive:find("user", {});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
122 assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
123 local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
124 for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
125 count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
126 assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
127 assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
128 assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
129 assert.equal("urn:example:foo", item.attr.xmlns);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
130 assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
131 assert.equal(test_data[count][3], when);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
132 end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
133 assert.equal(#test_data, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
134 end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
135
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
136 it("by JID", function ()
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
137 local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
138 with = "contact@example.com";
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
139 });
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
140 assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
141 local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
142 for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
143 count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
144 assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
145 assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
146 assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
147 assert.equal("urn:example:foo", item.attr.xmlns);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
148 assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
149 assert.equal(test_time, when);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
150 end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
151 assert.equal(1, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
152 end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
153
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
154 it("by time (end)", function ()
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
155 local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
156 ["end"] = test_time;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
157 });
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
158 assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
159 local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
160 for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
161 count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
162 assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
163 assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
164 assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
165 assert.equal("urn:example:foo", item.attr.xmlns);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
166 assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
167 assert(test_time >= when);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
168 end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
169 assert.equal(2, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
170 end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
171
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
172 it("by time (start)", function ()
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
173 local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
174 ["start"] = test_time;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
175 });
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
176 assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
177 local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
178 for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
179 count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
180 assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
181 assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
182 assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
183 assert.equal("urn:example:foo", item.attr.xmlns);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
184 assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
185 assert(test_time <= when);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
186 end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
187 assert.equal(#test_data -1, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
188 end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
189
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
190 it("by time (start+end)", function ()
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
191 local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
192 ["start"] = test_time;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
193 ["end"] = test_time+1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
194 });
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
195 assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
196 local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
197 for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
198 count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
199 assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
200 assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
201 assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
202 assert.equal("urn:example:foo", item.attr.xmlns);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
203 assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
204 assert(when >= test_time, ("%d >= %d"):format(when, test_time));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
205 assert(when <= test_time+1, ("%d <= %d"):format(when, test_time+1));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
206 end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
207 assert.equal(2, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
208 end);
9466
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
209 end);
9470
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9467
diff changeset
210
9471
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
211 it("can selectively delete items", function ()
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
212 local delete_id;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
213 do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
214 local data = assert(archive:find("user", {}));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
215 local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
216 for id, item, when in data do --luacheck: ignore 213/item 213/when
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
217 count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
218 if count == 2 then
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
219 delete_id = id;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
220 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
221 assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
222 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
223 assert.equal(#test_data, count);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
224 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
225
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
226 assert(archive:delete("user", { key = delete_id }));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
227
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
228 do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
229 local data = assert(archive:find("user", {}));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
230 local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
231 for id, item, when in data do --luacheck: ignore 213/item 213/when
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
232 count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
233 assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
234 assert.not_equal(delete_id, id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
235 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
236 assert.equal(#test_data-1, count);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
237 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
238 end);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
239
9466
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
240 it("can be purged", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
241 local ok, err = archive:delete("user");
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
242 assert.truthy(ok);
9467
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9466
diff changeset
243 local data, err = archive:find("user", {
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9466
diff changeset
244 with = "contact@example.com";
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9466
diff changeset
245 });
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9466
diff changeset
246 assert.truthy(data);
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9466
diff changeset
247 local count = 0;
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9466
diff changeset
248 for id, item, when in data do -- luacheck: ignore id item when
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9466
diff changeset
249 count = count + 1;
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9466
diff changeset
250 end
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9466
diff changeset
251 assert.equal(0, count);
9466
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9452
diff changeset
252 end);
9471
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
253
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
254 it("can truncate the oldest items", function ()
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
255 local username = "user-truncate";
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
256 for i = 1, 10 do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
257 assert(archive:append(username, nil, test_stanza, i, "contact@example.com"));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
258 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
259 assert(archive:delete(username, { truncate = 3 }));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
260
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
261 do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
262 local data = assert(archive:find(username, {}));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
263 local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
264 for id, item, when in data do --luacheck: ignore 213/when
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
265 count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
266 assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
267 assert(st.is_stanza(item));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
268 assert(when > 7, ("%d > 7"):format(when));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
269 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
270 assert.equal(3, count);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
271 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
272 end);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
273
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
274 it("overwrites existing keys with new data", function ()
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
275 local prefix = ("a"):rep(50);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
276 local username = "user-overwrite";
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
277 assert(archive:append(username, prefix.."-1", test_stanza, test_time, "contact@example.com"));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
278 assert(archive:append(username, prefix.."-2", test_stanza, test_time, "contact@example.com"));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
279
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
280 do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
281 local data = assert(archive:find(username, {}));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
282 local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
283 for id, item, when in data do --luacheck: ignore 213/when
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
284 count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
285 assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
286 assert.equals(("%s-%d"):format(prefix, count), id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
287 assert(st.is_stanza(item));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
288 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
289 assert.equal(2, count);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
290 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
291
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
292 local new_stanza = st.clone(test_stanza);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
293 new_stanza.attr.foo = "bar";
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
294 assert(archive:append(username, prefix.."-2", new_stanza, test_time+1, "contact2@example.com"));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
295
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
296 do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
297 local data = assert(archive:find(username, {}));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
298 local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
299 for id, item, when in data do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
300 count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
301 assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
302 assert.equals(("%s-%d"):format(prefix, count), id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
303 assert(st.is_stanza(item));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
304 if count == 2 then
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
305 assert.equals(test_time+1, when);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
306 assert.equals("bar", item.attr.foo);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
307 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
308 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
309 assert.equal(2, count);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
310 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
311 end);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
312
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
313 it("can contain multiple long unique keys #issue1073", function ()
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
314 local prefix = ("a"):rep(50);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
315 assert(archive:append("user-issue1073", prefix.."-1", test_stanza, test_time, "contact@example.com"));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
316 assert(archive:append("user-issue1073", prefix.."-2", test_stanza, test_time, "contact@example.com"));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
317
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
318 local data = assert(archive:find("user-issue1073", {}));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
319 local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
320 for id, item, when in data do --luacheck: ignore 213/when
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
321 count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
322 assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
323 assert(st.is_stanza(item));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
324 end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
325 assert.equal(2, count);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
326 assert(archive:delete("user-issue1073"));
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
327 end);
9389
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
328 end);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
329 end);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
330 end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
331 end);