[asterisk-commits] mnicholson: branch mnicholson/asttest r247253 - in /team/mnicholson/asttest/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 17 13:12:31 CST 2010


Author: mnicholson
Date: Wed Feb 17 13:12:28 2010
New Revision: 247253

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=247253
Log:
Add the ability to load configs from files.  The configs are not parsed at this time, they are simply copied verbatim.

Added:
    team/mnicholson/asttest/asttest/self-tests/astlib_load_config/
    team/mnicholson/asttest/asttest/self-tests/astlib_load_config/test.lua   (with props)
    team/mnicholson/asttest/asttest/self-tests/astlib_load_config_in_dir/
    team/mnicholson/asttest/asttest/self-tests/astlib_load_config_in_dir/dir/
    team/mnicholson/asttest/asttest/self-tests/astlib_load_config_in_dir/test.lua   (with props)
Modified:
    team/mnicholson/asttest/asttest/lua/astlib.lua

Modified: team/mnicholson/asttest/asttest/lua/astlib.lua
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/lua/astlib.lua?view=diff&rev=247253&r1=247252&r2=247253
==============================================================================
--- team/mnicholson/asttest/asttest/lua/astlib.lua (original)
+++ team/mnicholson/asttest/asttest/lua/astlib.lua Wed Feb 17 13:12:28 2010
@@ -99,6 +99,26 @@
 	end
 
 	return m
+end
+
+function asterisk:load_config(file, conf_name)
+	-- if conf_name is not specified, pull it from the string
+	if not conf_name then
+		if file:find("/") then
+			conf_name = file:match(".*/(.+)$")
+		else
+			conf_name = file
+		end
+	end
+
+	local f, err = io.open(file, "r");
+	if not f then
+		error("error opening file '" .. file .. "': " .. err)
+	end
+
+	local c = self:new_config(conf_name)
+	c:verbatim(f:read("*a"))
+	f:close()
 end
 
 function asterisk:new_config(name)

Added: team/mnicholson/asttest/asttest/self-tests/astlib_load_config/test.lua
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/self-tests/astlib_load_config/test.lua?view=auto&rev=247253
==============================================================================
--- team/mnicholson/asttest/asttest/self-tests/astlib_load_config/test.lua (added)
+++ team/mnicholson/asttest/asttest/self-tests/astlib_load_config/test.lua Wed Feb 17 13:12:28 2010
@@ -1,0 +1,42 @@
+-- test astlib
+
+-- generate what we expect to see
+expected_test_conf = [[
+[test]
+test = 1
+test = test
+value = this
+allow = true
+
+]]
+
+f = io.open("expected_test.conf", "w")
+f:write(expected_test_conf)
+f:close()
+
+
+-- load what we just wrote
+a = ast.new()
+a:load_config("expected_test.conf")
+a:spawn()
+a:term()
+
+test_conf_path = a.work_area .. "/etc/asterisk/expected_test.conf"
+
+f = io.open(test_conf_path)
+test_conf = f:read("*a")
+f:close()
+
+-- diff the two
+os.execute("diff -u expected_test.conf " .. test_conf_path .. " > diff")
+
+f = io.open("diff")
+diff = f:read("*a")
+f:close()
+
+-- cleanup
+os.execute("rm -f " .. test_conf_path .. " 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: team/mnicholson/asttest/asttest/self-tests/astlib_load_config/test.lua
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mnicholson/asttest/asttest/self-tests/astlib_load_config/test.lua
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mnicholson/asttest/asttest/self-tests/astlib_load_config/test.lua
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/mnicholson/asttest/asttest/self-tests/astlib_load_config_in_dir/test.lua
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/self-tests/astlib_load_config_in_dir/test.lua?view=auto&rev=247253
==============================================================================
--- team/mnicholson/asttest/asttest/self-tests/astlib_load_config_in_dir/test.lua (added)
+++ team/mnicholson/asttest/asttest/self-tests/astlib_load_config_in_dir/test.lua Wed Feb 17 13:12:28 2010
@@ -1,0 +1,42 @@
+-- test astlib
+
+-- generate what we expect to see
+expected_test_conf = [[
+[test]
+test = 1
+test = test
+value = this
+allow = true
+
+]]
+
+f = io.open("dir/expected_test.conf", "w")
+f:write(expected_test_conf)
+f:close()
+
+
+-- load what we just wrote
+a = ast.new()
+a:load_config("dir/expected_test.conf")
+a:spawn()
+a:term()
+
+test_conf_path = a.work_area .. "/etc/asterisk/expected_test.conf"
+
+f = io.open(test_conf_path)
+test_conf = f:read("*a")
+f:close()
+
+-- diff the two
+os.execute("diff -u dir/expected_test.conf " .. test_conf_path .. " > diff")
+
+f = io.open("diff")
+diff = f:read("*a")
+f:close()
+
+-- cleanup
+os.execute("rm -f " .. test_conf_path .. " dir/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: team/mnicholson/asttest/asttest/self-tests/astlib_load_config_in_dir/test.lua
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mnicholson/asttest/asttest/self-tests/astlib_load_config_in_dir/test.lua
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mnicholson/asttest/asttest/self-tests/astlib_load_config_in_dir/test.lua
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list