spec/core_storagemanager_spec.lua
author Matthew Wild <mwild1@gmail.com>
Wed, 11 Mar 2020 15:57:53 +0000
changeset 10681 0054aec3e8c5
parent 10680 33c7e4920591
child 10682 c9251d74a112
permissions -rw-r--r--
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9695
e11e076f0eb8 various: Don't rely on _G.unpack existing
Kim Alvefur <zash@zash.se>
parents: 9539
diff changeset
     1
local unpack = table.unpack or unpack; -- luacheck: ignore 113
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     2
local server = require "net.server_select";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     3
package.loaded["net.server"] = server;
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     4
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
     5
local st = require "util.stanza";
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
     6
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     7
local function mock_prosody()
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     8
	_G.prosody = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     9
		core_post_stanza = function () end;
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
		events = require "util.events".new();
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
		hosts = {};
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    12
		paths = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    13
			data = "./data";
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
	};
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    16
end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    17
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    18
local configs = {
9494
89e4cbd1a564 storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents: 9475
diff changeset
    19
	memory = {
89e4cbd1a564 storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents: 9475
diff changeset
    20
		storage = "memory";
89e4cbd1a564 storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents: 9475
diff changeset
    21
	};
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    22
	internal = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    23
		storage = "internal";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    24
	};
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    25
	sqlite = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    26
		storage = "sql";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    27
		sql = { driver = "SQLite3", database = "prosody-tests.sqlite" };
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    28
	};
9455
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    29
	mysql = {
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    30
		storage = "sql";
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    31
		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: 9392
diff changeset
    32
	};
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    33
	postgres = {
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    34
		storage = "sql";
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    35
		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: 9392
diff changeset
    36
	};
9392
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
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    39
local test_host = "storage-unit-tests.invalid";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    40
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    41
describe("storagemanager", function ()
9455
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    42
	for backend, backend_config in pairs(configs) do
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    43
		local tagged_name = "#"..backend;
9455
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    44
		if backend ~= backend_config.storage then
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    45
			tagged_name = tagged_name.." #"..backend_config.storage;
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    46
		end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    47
		insulate(tagged_name.." #storage backend", function ()
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    48
			mock_prosody();
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    49
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    50
			local config = require "core.configmanager";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    51
			local sm = require "core.storagemanager";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    52
			local hm = require "core.hostmanager";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    53
			local mm = require "core.modulemanager";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    54
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    55
			-- 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
    56
			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
    57
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    58
			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
    59
				config.set(test_host, k, v);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    60
			end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    61
			assert(hm.activate(test_host, {}));
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    62
			sm.initialize_host(test_host);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    63
			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
    64
10681
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
    65
			local sql_it = backend_config.sql and it or pending;
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
    66
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    67
			describe("key-value stores", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    68
				-- 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: 9455
diff changeset
    69
				-- randomization for this block
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    70
				randomize(false);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    71
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    72
				local store;
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    73
				it("may be opened", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    74
					store = assert(sm.open(test_host, "test"));
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    75
				end);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    76
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    77
				local simple_data = { foo = "bar" };
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    78
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    79
				it("may set data for a user", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    80
					assert(store:set("user9999", simple_data));
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    81
				end);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    82
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    83
				it("may get data for a user", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    84
					assert.same(simple_data, assert(store:get("user9999")));
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    85
				end);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    86
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    87
				it("may remove data for a user", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    88
					assert(store:set("user9999", nil));
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    89
					local ret, err = store:get("user9999");
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    90
					assert.is_nil(ret);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    91
					assert.is_nil(err);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    92
				end);
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    93
			end);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    94
10680
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    95
			describe("map stores", function ()
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    96
				-- These tests rely on being executed in order, disable any order
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    97
				-- randomization for this block
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    98
				randomize(false);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    99
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   100
				local store, kv_store;
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   101
				it("may be opened", function ()
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   102
					store = assert(sm.open(test_host, "test-map", "map"));
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   103
				end);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   104
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   105
				it("may be opened as a keyval store", function ()
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   106
					kv_store = assert(sm.open(test_host, "test-map", "keyval"));
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   107
				end);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   108
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   109
				it("may set a specific key for a user", function ()
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   110
					assert(store:set("user9999", "foo", "bar"));
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   111
					assert.same(kv_store:get("user9999"), { foo = "bar" });
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   112
				end);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   113
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   114
				it("may get a specific key for a user", function ()
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   115
					assert.equal("bar", store:get("user9999", "foo"));
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   116
				end);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   117
10681
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   118
				sql_it("may find all users with a specific key", function ()
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   119
					assert.is_function(store.find_key);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   120
					assert(store:set("user9999b", "bar", "bar"));
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   121
					assert(store:set("user9999c", "foo", "blah"));
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   122
					local ret, err = store:find_key("foo");
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   123
					assert.is_nil(err);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   124
					assert.same({ user9999 = "bar", user9999c = "blah" }, ret);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   125
				end);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   126
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   127
				sql_it("rejects empty or non-string keys to find_key", function ()
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   128
					assert.is_function(store.find_key);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   129
					do
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   130
						local ret, err = store:find_key("");
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   131
						assert.is_nil(ret);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   132
						assert.is_not_nil(err);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   133
					end
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   134
					do
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   135
						local ret, err = store:find_key(true);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   136
						assert.is_nil(ret);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   137
						assert.is_not_nil(err);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   138
					end
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   139
				end);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   140
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   141
				sql_it("rejects empty or non-string keys to delete_key", function ()
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   142
					assert.is_function(store.delete_key);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   143
					do
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   144
						local ret, err = store:delete_key("");
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   145
						assert.is_nil(ret);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   146
						assert.is_not_nil(err);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   147
					end
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   148
					do
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   149
						local ret, err = store:delete_key(true);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   150
						assert.is_nil(ret);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   151
						assert.is_not_nil(err);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   152
					end
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   153
				end);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   154
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   155
				sql_it("may delete all instances of a specific key", function ()
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   156
					assert.is_function(store.delete_key);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   157
					assert(store:set("user9999b", "foo", "hello"));
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   158
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   159
					local ret, err = store:delete_key("bar");
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   160
					-- Ensure key was deleted
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   161
					do
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   162
						local ret, err = store:get("user9999b", "bar");
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   163
						assert.is_nil(ret);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   164
						assert.is_nil(err);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   165
					end
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   166
					-- Ensure other users/keys are intact
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   167
					do
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   168
						local ret, err = store:get("user9999", "foo");
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   169
						assert.equal("bar", ret);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   170
						assert.is_nil(err);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   171
					end
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   172
					do
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   173
						local ret, err = store:get("user9999b", "foo");
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   174
						assert.equal("hello", ret);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   175
						assert.is_nil(err);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   176
					end
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   177
					do
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   178
						local ret, err = store:get("user9999c", "foo");
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   179
						assert.equal("blah", ret);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   180
						assert.is_nil(err);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   181
					end
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   182
				end);
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   183
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   184
				it("may remove data for a specific key for a user", function ()
10680
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   185
					assert(store:set("user9999", "foo", nil));
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   186
					do
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   187
						local ret, err = store:get("user9999", "foo");
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   188
						assert.is_nil(ret);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   189
						assert.is_nil(err);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   190
					end
10681
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   191
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   192
					assert(store:set("user9999b", "foo", nil));
10680
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   193
					do
10681
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   194
						local ret, err = store:get("user9999b", "foo");
10680
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   195
						assert.is_nil(ret);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   196
						assert.is_nil(err);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   197
					end
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   198
				end);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   199
			end);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   200
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   201
			describe("archive stores", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   202
				randomize(false);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   203
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   204
				local archive;
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   205
				it("can be opened", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   206
					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: 9455
diff changeset
   207
				end);
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   208
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   209
				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: 9455
diff changeset
   210
					:tag("foo"):up()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   211
					:tag("foo"):up();
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   212
				local test_time = 1539204123;
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   213
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   214
				local test_data = {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   215
					{ nil, test_stanza, test_time, "contact@example.com" };
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   216
					{ nil, test_stanza, test_time+1, "contact2@example.com" };
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   217
					{ nil, test_stanza, test_time+2, "contact2@example.com" };
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   218
					{ nil, test_stanza, test_time-1, "contact2@example.com" };
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   219
				};
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   220
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   221
				it("can be added to", function ()
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   222
					for _, data_item in ipairs(test_data) do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   223
						local ok = archive:append("user", unpack(data_item, 1, 4));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   224
						assert.truthy(ok);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   225
					end
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   226
				end);
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   227
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   228
				describe("can be queried", function ()
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   229
					it("for all items", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   230
						-- luacheck: ignore 211/err
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   231
						local data, err = archive:find("user", {});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   232
						assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   233
						local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   234
						for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   235
							count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   236
							assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   237
							assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   238
							assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   239
							assert.equal("urn:example:foo", item.attr.xmlns);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   240
							assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   241
							assert.equal(test_data[count][3], when);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   242
						end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   243
						assert.equal(#test_data, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   244
					end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   245
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   246
					it("by JID", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   247
						-- luacheck: ignore 211/err
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   248
						local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   249
							with = "contact@example.com";
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   250
						});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   251
						assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   252
						local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   253
						for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   254
							count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   255
							assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   256
							assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   257
							assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   258
							assert.equal("urn:example:foo", item.attr.xmlns);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   259
							assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   260
							assert.equal(test_time, when);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   261
						end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   262
						assert.equal(1, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   263
					end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   264
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   265
					it("by time (end)", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   266
						-- luacheck: ignore 211/err
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   267
						local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   268
							["end"] = test_time;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   269
						});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   270
						assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   271
						local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   272
						for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   273
							count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   274
							assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   275
							assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   276
							assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   277
							assert.equal("urn:example:foo", item.attr.xmlns);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   278
							assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   279
							assert(test_time >= when);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   280
						end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   281
						assert.equal(2, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   282
					end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   283
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   284
					it("by time (start)", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   285
						-- luacheck: ignore 211/err
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   286
						local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   287
							["start"] = test_time;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   288
						});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   289
						assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   290
						local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   291
						for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   292
							count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   293
							assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   294
							assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   295
							assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   296
							assert.equal("urn:example:foo", item.attr.xmlns);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   297
							assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   298
							assert(test_time <= when);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   299
						end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   300
						assert.equal(#test_data -1, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   301
					end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   302
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   303
					it("by time (start+end)", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   304
						-- luacheck: ignore 211/err
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   305
						local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   306
							["start"] = test_time;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   307
							["end"] = test_time+1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   308
						});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   309
						assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   310
						local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   311
						for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   312
							count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   313
							assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   314
							assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   315
							assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   316
							assert.equal("urn:example:foo", item.attr.xmlns);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   317
							assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   318
							assert(when >= test_time, ("%d >= %d"):format(when, test_time));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   319
							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: 9470
diff changeset
   320
						end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   321
						assert.equal(2, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   322
					end);
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   323
				end);
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   324
9474
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   325
				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: 9473
diff changeset
   326
					local delete_id;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   327
					do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   328
						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: 9473
diff changeset
   329
						local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   330
						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: 9473
diff changeset
   331
							count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   332
							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: 9473
diff changeset
   333
								delete_id = id;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   334
							end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   335
							assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   336
						end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   337
						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: 9473
diff changeset
   338
					end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   339
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   340
					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: 9473
diff changeset
   341
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   342
					do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   343
						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: 9473
diff changeset
   344
						local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   345
						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: 9473
diff changeset
   346
							count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   347
							assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   348
							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: 9473
diff changeset
   349
						end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   350
						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: 9473
diff changeset
   351
					end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   352
				end);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   353
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   354
				it("can be purged", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   355
					-- luacheck: ignore 211/err
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   356
					local ok, err = archive:delete("user");
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   357
					assert.truthy(ok);
9470
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   358
					local data, err = archive:find("user", {
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   359
						with = "contact@example.com";
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   360
					});
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   361
					assert.truthy(data);
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   362
					local count = 0;
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   363
					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: 9469
diff changeset
   364
						count = count + 1;
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   365
					end
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   366
					assert.equal(0, count);
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   367
				end);
9474
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   368
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   369
				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: 9473
diff changeset
   370
					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: 9473
diff changeset
   371
					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: 9473
diff changeset
   372
						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: 9473
diff changeset
   373
					end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   374
					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: 9473
diff changeset
   375
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   376
					do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   377
						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: 9473
diff changeset
   378
						local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   379
						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: 9473
diff changeset
   380
							count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   381
							assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   382
							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: 9473
diff changeset
   383
							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: 9473
diff changeset
   384
						end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   385
						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: 9473
diff changeset
   386
					end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   387
				end);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   388
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   389
				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: 9473
diff changeset
   390
					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: 9473
diff changeset
   391
					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: 9473
diff changeset
   392
					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: 9473
diff changeset
   393
					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: 9473
diff changeset
   394
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   395
					do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   396
						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: 9473
diff changeset
   397
						local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   398
						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: 9473
diff changeset
   399
							count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   400
							assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   401
							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: 9473
diff changeset
   402
							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: 9473
diff changeset
   403
						end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   404
						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: 9473
diff changeset
   405
					end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   406
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   407
					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: 9473
diff changeset
   408
					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: 9473
diff changeset
   409
					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: 9473
diff changeset
   410
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   411
					do
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   412
						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: 9473
diff changeset
   413
						local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   414
						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: 9473
diff changeset
   415
							count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   416
							assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   417
							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: 9473
diff changeset
   418
							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: 9473
diff changeset
   419
							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: 9473
diff changeset
   420
								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: 9473
diff changeset
   421
								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: 9473
diff changeset
   422
							end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   423
						end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   424
						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: 9473
diff changeset
   425
					end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   426
				end);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   427
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   428
				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: 9473
diff changeset
   429
					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: 9473
diff changeset
   430
					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: 9473
diff changeset
   431
					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: 9473
diff changeset
   432
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   433
					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: 9473
diff changeset
   434
					local count = 0;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   435
					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: 9473
diff changeset
   436
						count = count + 1;
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   437
						assert.truthy(id);
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   438
						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: 9473
diff changeset
   439
					end
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   440
					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: 9473
diff changeset
   441
					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: 9473
diff changeset
   442
				end);
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   443
			end);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   444
		end);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   445
	end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   446
end);