[asterisk-commits] mnicholson: testsuite/asterisk/trunk r181 - in /asterisk/trunk/asttest: lib/l...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Apr 2 12:01:44 CDT 2010
Author: mnicholson
Date: Fri Apr 2 12:01:41 2010
New Revision: 181
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=181
Log:
Make ast.asterisk implicitly create config files that are referenced but don't exist.
Added:
asterisk/trunk/asttest/self-tests/astlib_configs2/
asterisk/trunk/asttest/self-tests/astlib_configs2/test.lua (with props)
Modified:
asterisk/trunk/asttest/lib/lua/astlib.lua
Modified: asterisk/trunk/asttest/lib/lua/astlib.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/lib/lua/astlib.lua?view=diff&rev=181&r1=180&r2=181
==============================================================================
--- asterisk/trunk/asttest/lib/lua/astlib.lua (original)
+++ asterisk/trunk/asttest/lib/lua/astlib.lua Fri Apr 2 12:01:41 2010
@@ -96,12 +96,20 @@
end
end
+--- Index an asterisk object
+-- This function will return either the config with the given name, the actual
+-- table member with the given name, or if neither of those exist, it will
+-- create a config with the given name.
function asterisk:__index(key)
if self.configs[key] then
return self.configs[key]
end
- return asterisk[key]
+ if asterisk[key] ~= nil then
+ return asterisk[key]
+ end
+
+ return self:new_config(key)
end
function asterisk:manager_connect()
@@ -254,11 +262,20 @@
return s
end
+--- Index the config object
+-- This function will return the section of the config indicated if it exists,
+-- if it does not exist it will return the table data member with the given
+-- name if it exists, otherwise it will create a section with the given name
+-- and return that.
function config:__index(key)
local s = self.sections[self.section_index[key]]
if s then return s end
- return config[key]
+ if config[key] ~= nil then
+ return config[key]
+ end
+
+ return self:new_section(key)
end
function config:_write(filename)
Added: asterisk/trunk/asttest/self-tests/astlib_configs2/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/self-tests/astlib_configs2/test.lua?view=auto&rev=181
==============================================================================
--- asterisk/trunk/asttest/self-tests/astlib_configs2/test.lua (added)
+++ asterisk/trunk/asttest/self-tests/astlib_configs2/test.lua Fri Apr 2 12:01:41 2010
@@ -1,0 +1,92 @@
+-- test astlib
+
+skip_if(not ast.exists(), "asterisk not found")
+
+-- generate what we expect to see
+expected_test_conf = [[
+[test]
+test = 1
+test = test
+value = this
+allow = true
+
+[section]
+value = yes
+setting = on
+ip = 10.10.10.10
+
+[section]
+value = no
+
+#include file
+
+[template](!)
+value = default
+
+[inherit](template)
+value = default
+
+[inherit](template,test)
+value = default
+
+[inherit_template](!,template,test)
+value = default
+
+]]
+
+f = io.open("expected_test.conf", "w")
+f:write(expected_test_conf)
+f:close()
+
+
+-- generate a config
+a = ast.new()
+
+a["test.conf"]["test"]["test"] = 1
+a["test.conf"]["test"]["test"] = "test"
+a["test.conf"]["test"]["value"] = "this"
+a["test.conf"]["test"]["allow"] = true
+
+a["test.conf"]["section"]["value"] = "yes"
+a["test.conf"]["section"]["setting"] = "on"
+a["test.conf"]["section"]["ip"] = "10.10.10.10"
+
+s = a["test.conf"]:new_section("section")
+s["value"] = "no"
+
+a["test.conf"]:verbatim("#include file\n\n")
+
+a["test.conf"]["template"].template = true
+a["test.conf"]["template"]["value"] = "default"
+
+a["test.conf"]["inherit"].inherit = {"template"}
+a["test.conf"]["inherit"]["value"] = "default"
+
+s = a["test.conf"]:new_section("inherit")
+s.inherit = {"template", "test"}
+s["value"] = "default"
+
+a["test.conf"]["inherit_template"].template = true
+a["test.conf"]["inherit_template"].inherit = {"template", "test"}
+a["test.conf"]["inherit_template"]["value"] = "default"
+
+a:spawn()
+a:term_or_kill()
+
+f = io.open(a:path("/etc/asterisk/test.conf"))
+test_conf = f:read("*a")
+f:close()
+
+-- diff the two
+os.execute("diff -u expected_test.conf " .. a:path("/etc/asterisk/test.conf") .. " > diff")
+
+f = io.open("diff")
+diff = f:read("*a")
+f:close()
+
+-- cleanup
+os.execute("rm -f test.conf expected_test.conf diff")
+
+-- check if our two configs match
+fail_if(test_conf ~= expected_test_conf, "test_conf does not match expected_test_conf\n\n" .. diff)
+
Propchange: asterisk/trunk/asttest/self-tests/astlib_configs2/test.lua
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/asttest/self-tests/astlib_configs2/test.lua
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/asttest/self-tests/astlib_configs2/test.lua
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list