spec/core_configmanager_spec.lua
author Matthew Wild <mwild1@gmail.com>
Mon, 20 Feb 2023 18:10:15 +0000
branch0.12
changeset 12898 0598d822614f
parent 10499 8ea685ec0979
permissions -rw-r--r--
mod_websocket: Fire pre-session-close event (fixes #1800) This event was added in a7c183bb4e64 and is required to make mod_smacks know that a session was intentionally closed and shouldn't be hibernated (see fcea4d9e7502). Because this was missing from mod_websocket's session.close(), mod_smacks would always attempt to hibernate websocket sessions even if they closed cleanly. That mod_websocket has its own copy of session.close() is something to fix another day (probably not in the stable branch). So for now this commit makes the minimal change to get things working again. Thanks to Damian and the Jitsi team for reporting.


local configmanager = require "core.configmanager";

describe("core.configmanager", function()
	describe("#get()", function()
		it("should work", function()
			configmanager.set("example.com", "testkey", 123);
			assert.are.equal(123, configmanager.get("example.com", "testkey"), "Retrieving a set key");

			configmanager.set("*", "testkey1", 321);
			assert.are.equal(321, configmanager.get("*", "testkey1"), "Retrieving a set global key");
			assert.are.equal(321, configmanager.get("example.com", "testkey1"),
				"Retrieving a set key of undefined host, of which only a globally set one exists"
			);

			configmanager.set("example.com", ""); -- Creates example.com host in config
			assert.are.equal(321, configmanager.get("example.com", "testkey1"), "Retrieving a set key, of which only a globally set one exists");

			assert.are.equal(nil, configmanager.get(), "No parameters to get()");
			assert.are.equal(nil, configmanager.get("undefined host"), "Getting for undefined host");
			assert.are.equal(nil, configmanager.get("undefined host", "undefined key"), "Getting for undefined host & key");
		end);
	end);

	describe("#set()", function()
		it("should work", function()
			assert.are.equal(false, configmanager.set("*"), "Set with no key");

			assert.are.equal(true, configmanager.set("*", "set_test", "testkey"), "Setting a nil global value");
			assert.are.equal(true, configmanager.set("*", "set_test", "testkey", 123), "Setting a global value");
		end);
	end);
end);