spec/core_storagemanager_spec.lua
author Kim Alvefur <zash@zash.se>
Sat, 22 Jul 2023 16:17:13 +0200
changeset 13247 c5ccdfbbe9c1
parent 13137 3692265becb7
child 13248 2902c54f45a6
permissions -rw-r--r--
tests: Update storagemanager tests for prosody.* namespace change Part of an attempt to make these tests work again. Previously they would just explode in a million luarocks stack overflows
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12593
39ae08180c81 compat: Remove handling of Lua 5.1 location of 'unpack' function
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
     1
local unpack = table.unpack;
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     2
13247
c5ccdfbbe9c1 tests: Update storagemanager tests for prosody.* namespace change
Kim Alvefur <zash@zash.se>
parents: 13137
diff changeset
     3
local st = require "prosody.util.stanza";
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
     4
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     5
local function mock_prosody()
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     6
	_G.prosody = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     7
		core_post_stanza = function () end;
13247
c5ccdfbbe9c1 tests: Update storagemanager tests for prosody.* namespace change
Kim Alvefur <zash@zash.se>
parents: 13137
diff changeset
     8
		events = require "prosody.util.events".new();
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     9
		hosts = {};
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
		paths = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
			data = "./data";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    12
		};
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
end
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
local configs = {
9494
89e4cbd1a564 storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents: 9475
diff changeset
    17
	memory = {
89e4cbd1a564 storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents: 9475
diff changeset
    18
		storage = "memory";
89e4cbd1a564 storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents: 9475
diff changeset
    19
	};
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    20
	internal = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    21
		storage = "internal";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    22
	};
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    23
	sqlite = {
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    24
		storage = "sql";
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    25
		sql = { driver = "SQLite3", database = "prosody-tests.sqlite" };
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    26
	};
9455
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    27
	mysql = {
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    28
		storage = "sql";
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    29
		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
    30
	};
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    31
	postgres = {
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    32
		storage = "sql";
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    33
		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
    34
	};
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    35
};
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
local test_host = "storage-unit-tests.invalid";
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
describe("storagemanager", function ()
9455
9d892b2415bf Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents: 9392
diff changeset
    40
	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
    41
		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
    42
		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
    43
			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
    44
		end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    45
		insulate(tagged_name.." #storage backend", function ()
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    46
			mock_prosody();
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    47
13247
c5ccdfbbe9c1 tests: Update storagemanager tests for prosody.* namespace change
Kim Alvefur <zash@zash.se>
parents: 13137
diff changeset
    48
			local config = require "prosody.core.configmanager";
c5ccdfbbe9c1 tests: Update storagemanager tests for prosody.* namespace change
Kim Alvefur <zash@zash.se>
parents: 13137
diff changeset
    49
			local sm = require "prosody.core.storagemanager";
c5ccdfbbe9c1 tests: Update storagemanager tests for prosody.* namespace change
Kim Alvefur <zash@zash.se>
parents: 13137
diff changeset
    50
			local hm = require "prosody.core.hostmanager";
c5ccdfbbe9c1 tests: Update storagemanager tests for prosody.* namespace change
Kim Alvefur <zash@zash.se>
parents: 13137
diff changeset
    51
			local mm = require "prosody.core.modulemanager";
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    52
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    53
			-- 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
    54
			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
    55
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    56
			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
    57
				config.set(test_host, k, v);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    58
			end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    59
			assert(hm.activate(test_host, {}));
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    60
			sm.initialize_host(test_host);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    61
			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
    62
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    63
			describe("key-value stores", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    64
				-- 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
    65
				-- randomization for this block
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    66
				randomize(false);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    67
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    68
				local store;
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    69
				it("may be opened", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    70
					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
    71
				end);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    72
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    73
				local simple_data = { foo = "bar" };
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    74
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    75
				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
    76
					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
    77
				end);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    78
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    79
				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
    80
					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
    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 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
    84
					assert(store:set("user9999", nil));
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    85
					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
    86
					assert.is_nil(ret);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    87
					assert.is_nil(err);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
    88
				end);
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    89
			end);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    90
10680
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    91
			describe("map stores", function ()
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    92
				-- 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
    93
				-- randomization for this block
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    94
				randomize(false);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    95
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    96
				local store, kv_store;
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    97
				it("may be opened", function ()
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
    98
					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
    99
				end);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   100
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   101
				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
   102
					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
   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 set a specific key for a user", function ()
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   106
					assert(store:set("user9999", "foo", "bar"));
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   107
					assert.same(kv_store:get("user9999"), { foo = "bar" });
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   108
				end);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   109
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   110
				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
   111
					assert.equal("bar", store:get("user9999", "foo"));
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
10683
b50b1eae711c storagemanager: Add support for :find_key() and :delete_key() to map store shim
Matthew Wild <mwild1@gmail.com>
parents: 10682
diff changeset
   114
				it("may find all users with a specific key", function ()
10684
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   115
					assert.is_function(store.get_all);
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
   116
					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
   117
					assert(store:set("user9999c", "foo", "blah"));
10684
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   118
					local ret, err = store:get_all("foo");
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
   119
					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
   120
					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
   121
				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
   122
10684
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   123
				it("rejects empty or non-string keys to get_all", function ()
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   124
					assert.is_function(store.get_all);
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
   125
					do
10684
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   126
						local ret, err = store:get_all("");
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
   127
						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
   128
						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
   129
					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
   130
					do
10684
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   131
						local ret, err = store:get_all(true);
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
   132
						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
   133
						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
   134
					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
   135
				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
   136
10684
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   137
				it("rejects empty or non-string keys to delete_all", function ()
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   138
					assert.is_function(store.delete_all);
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
   139
					do
10684
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   140
						local ret, err = store:delete_all("");
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
   141
						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
   142
						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
   143
					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
   144
					do
10684
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   145
						local ret, err = store:delete_all(true);
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
   146
						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
   147
						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
   148
					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
   149
				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
   150
10683
b50b1eae711c storagemanager: Add support for :find_key() and :delete_key() to map store shim
Matthew Wild <mwild1@gmail.com>
parents: 10682
diff changeset
   151
				it("may delete all instances of a specific key", function ()
10684
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   152
					assert.is_function(store.delete_all);
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
   153
					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
   154
10684
19692fc5c106 storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents: 10683
diff changeset
   155
					assert(store:delete_all("bar"));
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
   156
					-- 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
   157
					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
   158
						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
   159
						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
   160
						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
   161
					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
   162
					-- 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
   163
					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
   164
						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
   165
						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
   166
						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
   167
					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
   168
					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
   169
						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
   170
						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
   171
						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
   172
					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
   173
					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
   174
						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
   175
						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
   176
						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
   177
					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
   178
				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
   179
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
				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
   181
					assert(store:set("user9999", "foo", nil));
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   182
					do
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   183
						local ret, err = store:get("user9999", "foo");
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   184
						assert.is_nil(ret);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   185
						assert.is_nil(err);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   186
					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
   187
0054aec3e8c5 mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents: 10680
diff changeset
   188
					assert(store:set("user9999b", "foo", nil));
10680
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   189
					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
   190
						local ret, err = store:get("user9999b", "foo");
10680
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   191
						assert.is_nil(ret);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   192
						assert.is_nil(err);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   193
					end
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   194
				end);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   195
			end);
33c7e4920591 storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents: 10545
diff changeset
   196
12960
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   197
			describe("keyval+ stores", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   198
				-- These tests rely on being executed in order, disable any order
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   199
				-- randomization for this block
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   200
				randomize(false);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   201
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   202
				local store, kv_store, map_store;
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   203
				it("may be opened", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   204
					store = assert(sm.open(test_host, "test-kv+", "keyval+"));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   205
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   206
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   207
				local simple_data = { foo = "bar" };
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   208
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   209
				it("may set data for a user", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   210
					assert(store:set("user9999", simple_data));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   211
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   212
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   213
				it("may get data for a user", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   214
					assert.same(simple_data, assert(store:get("user9999")));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   215
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   216
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   217
				it("may be opened as a keyval store", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   218
					kv_store = assert(sm.open(test_host, "test-kv+", "keyval"));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   219
					assert.same(simple_data, assert(kv_store:get("user9999")));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   220
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   221
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   222
				it("may be opened as a map store", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   223
					map_store = assert(sm.open(test_host, "test-kv+", "map"));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   224
					assert.same("bar", assert(map_store:get("user9999", "foo")));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   225
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   226
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   227
				it("may remove data for a user", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   228
					assert(store:set("user9999", nil));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   229
					local ret, err = store:get("user9999");
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   230
					assert.is_nil(ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   231
					assert.is_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   232
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   233
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   234
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   235
				it("may set a specific key for a user", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   236
					assert(store:set_key("user9999", "foo", "bar"));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   237
					assert.same(kv_store:get("user9999"), { foo = "bar" });
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   238
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   239
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   240
				it("may get a specific key for a user", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   241
					assert.equal("bar", store:get_key("user9999", "foo"));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   242
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   243
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   244
				it("may find all users with a specific key", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   245
					assert.is_function(store.get_key_from_all);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   246
					assert(store:set_key("user9999b", "bar", "bar"));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   247
					assert(store:set_key("user9999c", "foo", "blah"));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   248
					local ret, err = store:get_key_from_all("foo");
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   249
					assert.is_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   250
					assert.same({ user9999 = "bar", user9999c = "blah" }, ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   251
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   252
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   253
				it("rejects empty or non-string keys to get_all", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   254
					assert.is_function(store.get_key_from_all);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   255
					do
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   256
						local ret, err = store:get_key_from_all("");
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   257
						assert.is_nil(ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   258
						assert.is_not_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   259
					end
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   260
					do
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   261
						local ret, err = store:get_key_from_all(true);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   262
						assert.is_nil(ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   263
						assert.is_not_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   264
					end
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   265
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   266
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   267
				it("rejects empty or non-string keys to delete_all", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   268
					assert.is_function(store.delete_key_from_all);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   269
					do
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   270
						local ret, err = store:delete_key_from_all("");
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   271
						assert.is_nil(ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   272
						assert.is_not_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   273
					end
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   274
					do
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   275
						local ret, err = store:delete_key_from_all(true);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   276
						assert.is_nil(ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   277
						assert.is_not_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   278
					end
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   279
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   280
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   281
				it("may delete all instances of a specific key", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   282
					assert.is_function(store.delete_key_from_all);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   283
					assert(store:set_key("user9999b", "foo", "hello"));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   284
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   285
					assert(store:delete_key_from_all("bar"));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   286
					-- Ensure key was deleted
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   287
					do
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   288
						local ret, err = store:get_key("user9999b", "bar");
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   289
						assert.is_nil(ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   290
						assert.is_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   291
					end
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   292
					-- Ensure other users/keys are intact
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   293
					do
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   294
						local ret, err = store:get_key("user9999", "foo");
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   295
						assert.equal("bar", ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   296
						assert.is_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   297
					end
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   298
					do
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   299
						local ret, err = store:get_key("user9999b", "foo");
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   300
						assert.equal("hello", ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   301
						assert.is_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   302
					end
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   303
					do
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   304
						local ret, err = store:get_key("user9999c", "foo");
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   305
						assert.equal("blah", ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   306
						assert.is_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   307
					end
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   308
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   309
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   310
				it("may remove data for a specific key for a user", function ()
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   311
					assert(store:set_key("user9999", "foo", nil));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   312
					do
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   313
						local ret, err = store:get_key("user9999", "foo");
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   314
						assert.is_nil(ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   315
						assert.is_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   316
					end
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   317
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   318
					assert(store:set_key("user9999b", "foo", nil));
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   319
					do
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   320
						local ret, err = store:get_key("user9999b", "foo");
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   321
						assert.is_nil(ret);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   322
						assert.is_nil(err);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   323
					end
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   324
				end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   325
			end);
52fcdfe710ca storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents: 12604
diff changeset
   326
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   327
			describe("archive stores", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   328
				randomize(false);
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   329
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   330
				local archive;
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   331
				it("can be opened", function ()
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   332
					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
   333
				end);
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   334
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   335
				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
   336
					:tag("foo"):up()
10840
93019f3edd68 spec/storage: Reset build context of test stanza make comparisons easier
Kim Alvefur <zash@zash.se>
parents: 10684
diff changeset
   337
					:tag("foo"):up()
93019f3edd68 spec/storage: Reset build context of test stanza make comparisons easier
Kim Alvefur <zash@zash.se>
parents: 10684
diff changeset
   338
					:reset();
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   339
				local test_time = 1539204123;
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   340
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   341
				local test_data = {
13137
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   342
					{ nil, test_stanza, test_time-3, "contact@example.com" };
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   343
					{ nil, test_stanza, test_time-2, "contact2@example.com" };
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   344
					{ nil, test_stanza, test_time-1, "contact2@example.com" };
13137
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   345
					{ nil, test_stanza, test_time+0, "contact2@example.com" };
10931
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   346
					{ nil, test_stanza, test_time+1, "contact3@example.com" };
13137
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   347
					{ nil, test_stanza, test_time+2, "contact3@example.com" };
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   348
					{ nil, test_stanza, test_time+3, "contact3@example.com" };
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   349
				};
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   350
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   351
				it("can be added to", function ()
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   352
					for _, data_item in ipairs(test_data) do
10931
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   353
						local id = archive:append("user", unpack(data_item, 1, 4));
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   354
						assert.truthy(id);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   355
						data_item[1] = id;
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   356
					end
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   357
				end);
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   358
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   359
				describe("can be queried", function ()
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   360
					it("for all items", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   361
						-- luacheck: ignore 211/err
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   362
						local data, err = archive:find("user", {});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   363
						assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   364
						local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   365
						for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   366
							count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   367
							assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   368
							assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   369
							assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   370
							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
   371
							assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   372
							assert.equal(test_data[count][3], when);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   373
						end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   374
						assert.equal(#test_data, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   375
					end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   376
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   377
					it("by JID", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   378
						-- luacheck: ignore 211/err
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   379
						local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   380
							with = "contact@example.com";
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   381
						});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   382
						assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   383
						local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   384
						for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   385
							count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   386
							assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   387
							assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   388
							assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   389
							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
   390
							assert.equal(2, #item.tags);
13137
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   391
							assert.equal(test_time-3, when);
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   392
						end
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   393
						assert.equal(1, count);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   394
					end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   395
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   396
					it("by time (end)", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   397
						-- luacheck: ignore 211/err
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   398
						local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   399
							["end"] = test_time;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   400
						});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   401
						assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   402
						local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   403
						for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   404
							count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   405
							assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   406
							assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   407
							assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   408
							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
   409
							assert.equal(2, #item.tags);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   410
							assert(test_time >= when);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   411
						end
10931
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   412
						assert.equal(4, count);
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   413
					end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   414
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   415
					it("by time (start)", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   416
						-- luacheck: ignore 211/err
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   417
						local data, err = archive:find("user", {
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   418
							["start"] = test_time;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   419
						});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   420
						assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   421
						local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   422
						for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   423
							count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   424
							assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   425
							assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   426
							assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   427
							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
   428
							assert.equal(2, #item.tags);
13137
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   429
							assert(when >= test_time, ("%d >= %d"):format(when, test_time));
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   430
						end
13137
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   431
						assert.equal(#test_data - 3, count);
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   432
					end);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   433
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   434
					it("by time (start+end)", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   435
						-- luacheck: ignore 211/err
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   436
						local data, err = archive:find("user", {
13137
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   437
							["start"] = test_time-1;
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   438
							["end"] = test_time+2;
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   439
						});
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   440
						assert.truthy(data);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   441
						local count = 0;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   442
						for id, item, when in data do
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   443
							count = count + 1;
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   444
							assert.truthy(id);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   445
							assert(st.is_stanza(item));
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   446
							assert.equal("test", item.name);
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   447
							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
   448
							assert.equal(2, #item.tags);
13137
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   449
							assert(when >= test_time-1, ("%d >= %d"):format(when, test_time));
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   450
							assert(when <= test_time+2, ("%d <= %d"):format(when, test_time+1));
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   451
						end
10931
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   452
						assert.equal(4, count);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   453
					end);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   454
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   455
					it("by id (after)", function ()
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   456
						-- luacheck: ignore 211/err
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   457
						local data, err = archive:find("user", {
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   458
							["after"] = test_data[2][1];
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   459
						});
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   460
						assert.truthy(data);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   461
						local count = 0;
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   462
						for id, item in data do
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   463
							count = count + 1;
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   464
							assert.truthy(id);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   465
							assert.equal(test_data[2+count][1], id);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   466
							assert(st.is_stanza(item));
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   467
							assert.equal("test", item.name);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   468
							assert.equal("urn:example:foo", item.attr.xmlns);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   469
							assert.equal(2, #item.tags);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   470
						end
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   471
						assert.equal(5, count);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   472
					end);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   473
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   474
					it("by id (before)", function ()
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   475
						-- luacheck: ignore 211/err
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   476
						local data, err = archive:find("user", {
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   477
							["before"] = test_data[4][1];
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   478
						});
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   479
						assert.truthy(data);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   480
						local count = 0;
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   481
						for id, item in data do
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   482
							count = count + 1;
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   483
							assert.truthy(id);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   484
							assert.equal(test_data[count][1], id);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   485
							assert(st.is_stanza(item));
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   486
							assert.equal("test", item.name);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   487
							assert.equal("urn:example:foo", item.attr.xmlns);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   488
							assert.equal(2, #item.tags);
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   489
						end
470602a8b633 storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents: 10846
diff changeset
   490
						assert.equal(3, count);
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   491
					end);
11277
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   492
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   493
					it("by id (before and after) #full_id_range", function ()
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   494
						assert.truthy(archive.caps and archive.caps.full_id_range, "full ID range support")
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   495
						local data, err = archive:find("user", {
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   496
								["after"] = test_data[1][1];
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   497
								["before"] = test_data[4][1];
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   498
							});
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   499
						assert.truthy(data, err);
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   500
						local count = 0;
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   501
						for id, item in data do
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   502
							count = count + 1;
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   503
							assert.truthy(id);
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   504
							assert.equal(test_data[1+count][1], id);
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   505
							assert(st.is_stanza(item));
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   506
							assert.equal("test", item.name);
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   507
							assert.equal("urn:example:foo", item.attr.xmlns);
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   508
							assert.equal(2, #item.tags);
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   509
						end
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   510
						assert.equal(2, count);
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   511
					end);
9f1355689648 storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents: 10931
diff changeset
   512
11280
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   513
					it("by multiple ids", function ()
11428
2358299bc928 core.storagemanager: s/Multilpe/Multiple/ [codespell]
Kim Alvefur <zash@zash.se>
parents: 11358
diff changeset
   514
						assert.truthy(archive.caps and archive.caps.ids, "Multiple ID query")
11280
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   515
						local data, err = archive:find("user", {
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   516
								["ids"] = {
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   517
									test_data[2][1];
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   518
									test_data[4][1];
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   519
								};
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   520
							});
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   521
						assert.truthy(data, err);
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   522
						local count = 0;
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   523
						for id, item in data do
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   524
							count = count + 1;
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   525
							assert.truthy(id);
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   526
							assert.equal(test_data[count==1 and 2 or 4][1], id);
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   527
							assert(st.is_stanza(item));
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   528
							assert.equal("test", item.name);
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   529
							assert.equal("urn:example:foo", item.attr.xmlns);
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   530
							assert.equal(2, #item.tags);
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   531
						end
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   532
						assert.equal(2, count);
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   533
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   534
					end);
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   535
7b2ee8995af9 storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents: 11277
diff changeset
   536
11357
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   537
					it("can be queried in reverse", function ()
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   538
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   539
						local data, err = archive:find("user", {
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   540
								reverse = true;
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   541
								limit = 3;
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   542
							});
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   543
						assert.truthy(data, err);
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   544
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   545
						local i = #test_data;
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   546
						for id, item in data do
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   547
							assert.truthy(id);
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   548
							assert.equal(test_data[i][1], id);
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   549
							assert(st.is_stanza(item));
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   550
							assert.equal("test", item.name);
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   551
							assert.equal("urn:example:foo", item.attr.xmlns);
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   552
							assert.equal(2, #item.tags);
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   553
							i = i - 1;
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   554
						end
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   555
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   556
					end);
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   557
367e6beaf8ab storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents: 11280
diff changeset
   558
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   559
				end);
9473
0d491bc98b9f storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents: 9470
diff changeset
   560
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
   561
				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
   562
					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
   563
					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
   564
						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
   565
						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
   566
						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
   567
							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
   568
							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
   569
								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
   570
							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
   571
							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
   572
						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
   573
						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
   574
					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
   575
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   576
					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
   577
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   578
					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
   579
						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
   580
						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
   581
						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
   582
							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
   583
							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
   584
							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
   585
						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
   586
						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
   587
					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
   588
				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
   589
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   590
				it("can be purged", function ()
10545
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 9695
diff changeset
   591
					-- luacheck: ignore 211/err
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   592
					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
   593
					assert.truthy(ok);
9470
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   594
					local data, err = archive:find("user", {
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   595
						with = "contact@example.com";
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   596
					});
13137
3692265becb7 storagemanager tests: Reorder test data in chronological order
Kim Alvefur <zash@zash.se>
parents: 12960
diff changeset
   597
					assert.truthy(data, err);
9470
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   598
					local count = 0;
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   599
					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
   600
						count = count + 1;
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   601
					end
2098794ac866 storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents: 9469
diff changeset
   602
					assert.equal(0, count);
9469
b70ce39d366f storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents: 9455
diff changeset
   603
				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
   604
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   605
				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
   606
					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
   607
					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
   608
						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
   609
					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
   610
					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
   611
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   612
					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
   613
						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
   614
						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
   615
						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
   616
							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
   617
							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
   618
							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
   619
							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
   620
						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
   621
						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
   622
					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
   623
				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
   624
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   625
				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
   626
					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
   627
					local username = "user-overwrite";
11743
e0d0680e04cc core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents: 11428
diff changeset
   628
					local a1 = assert(archive:append(username, prefix.."-1", test_stanza, test_time, "contact@example.com"));
e0d0680e04cc core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents: 11428
diff changeset
   629
					local a2 = assert(archive:append(username, prefix.."-2", test_stanza, test_time, "contact@example.com"));
e0d0680e04cc core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents: 11428
diff changeset
   630
					local ids = { a1, a2, };
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
   631
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   632
					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
   633
						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
   634
						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
   635
						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
   636
							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
   637
							assert.truthy(id);
11743
e0d0680e04cc core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents: 11428
diff changeset
   638
							assert.equals(ids[count], id);
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
   639
							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
   640
						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
   641
						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
   642
					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
   643
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   644
					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
   645
					new_stanza.attr.foo = "bar";
11743
e0d0680e04cc core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents: 11428
diff changeset
   646
					assert(archive:append(username, a2, new_stanza, test_time+1, "contact2@example.com"));
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
   647
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   648
					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
   649
						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
   650
						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
   651
						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
   652
							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
   653
							assert.truthy(id);
11743
e0d0680e04cc core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents: 11428
diff changeset
   654
							assert.equals(ids[count], id);
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
   655
							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
   656
							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
   657
								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
   658
								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
   659
							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
   660
						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
   661
						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
   662
					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
   663
				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
   664
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   665
				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
   666
					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
   667
					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
   668
					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
   669
6798fcd25e9c storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents: 9473
diff changeset
   670
					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
   671
					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
   672
					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
   673
						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
   674
						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
   675
						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
   676
					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
   677
					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
   678
					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
   679
				end);
10841
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   680
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   681
				it("can be treated as a map store", function ()
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   682
					assert.falsy(archive:get("mapuser", "no-such-id"));
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   683
					assert.falsy(archive:set("mapuser", "no-such-id", test_stanza));
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   684
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   685
					local id = archive:append("mapuser", nil, test_stanza, test_time, "contact@example.com");
10846
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   686
					do
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   687
						local stanza_roundtrip, when, with = archive:get("mapuser", id);
11358
10fba62332c5 mod_storage_sql: Implement map-like API for archives
Kim Alvefur <zash@zash.se>
parents: 11357
diff changeset
   688
						assert.same(tostring(test_stanza), tostring(stanza_roundtrip), "same stanza is returned");
10846
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   689
						assert.equal(test_time, when, "same 'when' is returned");
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   690
						assert.equal("contact@example.com", with, "same 'with' is returned");
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   691
					end
10841
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   692
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   693
					local replacement_stanza = st.stanza("test", { xmlns = "urn:example:foo" })
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   694
						:tag("bar"):up()
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   695
						:reset();
10846
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   696
					assert(archive:set("mapuser", id, replacement_stanza, test_time+1));
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   697
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   698
					do
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   699
						local replaced, when, with = archive:get("mapuser", id);
11358
10fba62332c5 mod_storage_sql: Implement map-like API for archives
Kim Alvefur <zash@zash.se>
parents: 11357
diff changeset
   700
						assert.same(tostring(replacement_stanza), tostring(replaced), "replaced stanza is returned");
10846
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   701
						assert.equal(test_time+1, when, "modified 'when' is returned");
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   702
						assert.equal("contact@example.com", with, "original 'with' is returned");
5a6ba2f38e2b mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents: 10841
diff changeset
   703
					end
10841
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   704
				end);
f23363380599 mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents: 10840
diff changeset
   705
12602
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   706
				it("the summary api works", function()
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   707
					assert.truthy(archive:delete("summary-user"));
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   708
					local first_sid = archive:append("summary-user", nil, test_stanza, test_time, "contact@example.com");
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   709
					local second_sid = archive:append("summary-user", nil, test_stanza, test_time+1, "contact@example.com");
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   710
					assert.truthy(first_sid and second_sid, "preparations failed")
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   711
					---
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   712
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   713
					local user_summary, err = archive:summary("summary-user");
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   714
					assert.is_table(user_summary, err);
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   715
					assert.same({ ["contact@example.com"] = 2 }, user_summary.counts, "summary.counts matches");
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   716
					assert.same({ ["contact@example.com"] = test_time }, user_summary.earliest, "summary.earliest matches");
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   717
					assert.same({ ["contact@example.com"] = test_time+1 }, user_summary.latest, "summary.latest matches");
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   718
					if user_summary.body then
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   719
						assert.same({ ["contact@example.com"] = test_stanza:get_child_text("body") }, user_summary.body, "summary.body matches");
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   720
					end
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   721
				end);
a2624315d30e storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents: 11743
diff changeset
   722
9392
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   723
			end);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   724
		end);
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   725
	end
9ae575efbb1f Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   726
end);