Software /
code /
prosody
Comparison
spec/core_storagemanager_spec.lua @ 9470:0d491bc98b9f
storagemanager tests: Add additional archive query tests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 11 Oct 2018 13:29:14 +0100 |
parent | 9467:2098794ac866 |
child | 9471:6798fcd25e9c |
comparison
equal
deleted
inserted
replaced
9469:cd2f742e5826 | 9470:0d491bc98b9f |
---|---|
96 | 96 |
97 local test_stanza = st.stanza("test", { xmlns = "urn:example:foo" }) | 97 local test_stanza = st.stanza("test", { xmlns = "urn:example:foo" }) |
98 :tag("foo"):up() | 98 :tag("foo"):up() |
99 :tag("foo"):up(); | 99 :tag("foo"):up(); |
100 local test_time = 1539204123; | 100 local test_time = 1539204123; |
101 | |
102 local test_data = { | |
103 { nil, test_stanza, test_time, "contact@example.com" }; | |
104 { nil, test_stanza, test_time+1, "contact2@example.com" }; | |
105 { nil, test_stanza, test_time+2, "contact2@example.com" }; | |
106 { nil, test_stanza, test_time-1, "contact2@example.com" }; | |
107 }; | |
108 | |
101 it("can be added to", function () | 109 it("can be added to", function () |
102 local ok = archive:append("user", nil, test_stanza, 1539204123, "contact@example.com"); | 110 for _, data_item in ipairs(test_data) do |
103 assert.truthy(ok); | 111 local ok = archive:append("user", unpack(data_item, 1, 4)); |
104 end); | 112 assert.truthy(ok); |
105 | |
106 it("can be queried", function () | |
107 local data, err = archive:find("user", { | |
108 with = "contact@example.com"; | |
109 }); | |
110 assert.truthy(data); | |
111 local count = 0; | |
112 for id, item, when in data do | |
113 count = count + 1; | |
114 assert.truthy(id); | |
115 assert(st.is_stanza(item)); | |
116 assert.equal("test", item.name); | |
117 assert.equal("urn:example:foo", item.attr.xmlns); | |
118 assert.equal(2, #item.tags); | |
119 assert.equal(test_time, when); | |
120 end | 113 end |
121 assert.equal(1, count); | 114 end); |
122 end); | 115 |
116 describe("can be queried", function () | |
117 it("for all items", function () | |
118 local data, err = archive:find("user", {}); | |
119 assert.truthy(data); | |
120 local count = 0; | |
121 for id, item, when in data do | |
122 count = count + 1; | |
123 assert.truthy(id); | |
124 assert(st.is_stanza(item)); | |
125 assert.equal("test", item.name); | |
126 assert.equal("urn:example:foo", item.attr.xmlns); | |
127 assert.equal(2, #item.tags); | |
128 assert.equal(test_data[count][3], when); | |
129 end | |
130 assert.equal(#test_data, count); | |
131 end); | |
132 | |
133 it("by JID", function () | |
134 local data, err = archive:find("user", { | |
135 with = "contact@example.com"; | |
136 }); | |
137 assert.truthy(data); | |
138 local count = 0; | |
139 for id, item, when in data do | |
140 count = count + 1; | |
141 assert.truthy(id); | |
142 assert(st.is_stanza(item)); | |
143 assert.equal("test", item.name); | |
144 assert.equal("urn:example:foo", item.attr.xmlns); | |
145 assert.equal(2, #item.tags); | |
146 assert.equal(test_time, when); | |
147 end | |
148 assert.equal(1, count); | |
149 end); | |
150 | |
151 it("by time (end)", function () | |
152 local data, err = archive:find("user", { | |
153 ["end"] = test_time; | |
154 }); | |
155 assert.truthy(data); | |
156 local count = 0; | |
157 for id, item, when in data do | |
158 count = count + 1; | |
159 assert.truthy(id); | |
160 assert(st.is_stanza(item)); | |
161 assert.equal("test", item.name); | |
162 assert.equal("urn:example:foo", item.attr.xmlns); | |
163 assert.equal(2, #item.tags); | |
164 assert(test_time >= when); | |
165 end | |
166 assert.equal(2, count); | |
167 end); | |
168 | |
169 it("by time (start)", function () | |
170 local data, err = archive:find("user", { | |
171 ["start"] = test_time; | |
172 }); | |
173 assert.truthy(data); | |
174 local count = 0; | |
175 for id, item, when in data do | |
176 count = count + 1; | |
177 assert.truthy(id); | |
178 assert(st.is_stanza(item)); | |
179 assert.equal("test", item.name); | |
180 assert.equal("urn:example:foo", item.attr.xmlns); | |
181 assert.equal(2, #item.tags); | |
182 assert(test_time <= when); | |
183 end | |
184 assert.equal(#test_data -1, count); | |
185 end); | |
186 | |
187 it("by time (start+end)", function () | |
188 local data, err = archive:find("user", { | |
189 ["start"] = test_time; | |
190 ["end"] = test_time+1; | |
191 }); | |
192 assert.truthy(data); | |
193 local count = 0; | |
194 for id, item, when in data do | |
195 count = count + 1; | |
196 assert.truthy(id); | |
197 assert(st.is_stanza(item)); | |
198 assert.equal("test", item.name); | |
199 assert.equal("urn:example:foo", item.attr.xmlns); | |
200 assert.equal(2, #item.tags); | |
201 assert(when >= test_time, ("%d >= %d"):format(when, test_time)); | |
202 assert(when <= test_time+1, ("%d <= %d"):format(when, test_time+1)); | |
203 end | |
204 assert.equal(2, count); | |
205 end); | |
206 end); | |
207 | |
123 it("can be purged", function () | 208 it("can be purged", function () |
124 local ok, err = archive:delete("user"); | 209 local ok, err = archive:delete("user"); |
125 assert.truthy(ok); | 210 assert.truthy(ok); |
126 local data, err = archive:find("user", { | 211 local data, err = archive:find("user", { |
127 with = "contact@example.com"; | 212 with = "contact@example.com"; |