[asterisk-commits] mnicholson: testsuite/asterisk/trunk r796 - in /asterisk/trunk/tests/cdr: app...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 29 10:41:52 CDT 2010


Author: mnicholson
Date: Wed Sep 29 10:41:49 2010
New Revision: 796

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=796
Log:
Use the lua cdr lib for CDR parsing.

Modified:
    asterisk/trunk/tests/cdr/app_queue/test.lua
    asterisk/trunk/tests/cdr/blind-transfer-accountcode/test.lua
    asterisk/trunk/tests/cdr/originate-cdr-disposition/test.lua

Modified: asterisk/trunk/tests/cdr/app_queue/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/app_queue/test.lua?view=diff&rev=796&r1=795&r2=796
==============================================================================
--- asterisk/trunk/tests/cdr/app_queue/test.lua (original)
+++ asterisk/trunk/tests/cdr/app_queue/test.lua Wed Sep 29 10:41:49 2010
@@ -1,10 +1,5 @@
 
-function check(msg, r, err)
-	if not r then
-		error(msg .. ": " .. err)
-	end
-	return r
-end
+require "cdr"
 
 function mcheck(msg, r, err)
 	check(msg, r, err)
@@ -53,39 +48,17 @@
 
 function check_cdr_disposition(a, record, disposition)
 	print("checking CDR")
-	local cdr_path = a:path("/var/log/asterisk/cdr-csv/Master.csv")
-	local f, err = io.open(cdr_path, "r")
-	if not f then
-		error("error opening cdr file (" .. cdr_path .. "): " .. err)
-	end
+	local c = check("error parsing cdr file", cdr.new(a))
 
-	local found = false
-	local lineno = 0
-	for line in f:lines() do
-		lineno = lineno + 1
-
-		if lineno == record then
-			fail_if(not line:find(string.format('"%s"', disposition)), string.format("did not find disposition '%s' on line %s of cdr:\n%s", disposition, lineno, line))
-			found = true
-			break
-		end
-	end
-	fail_if(not found, string.format("expected disposition '%s' on line %s of cdr, but line %s does not exist in the file", disposition, record, record))
+	fail_if(not c[record], string.format("expected disposition '%s' in record %s, but file only has %s record(s)", disposition, record, c:len()))
+	fail_if(c[record]["disposition"] ~= disposition, string.format("expected disposition '%s' in record %s, but found '%s'", disposition, record, tostring(c[record]["disposition"])))
 end
 
 function check_for_n_cdrs(a, records)
-	local cdr_path = a:path("/var/log/asterisk/cdr-csv/Master.csv")
-	local f, err = io.open(cdr_path, "r")
-	if not f then
-		error("error opening cdr file (" .. cdr_path .. "): " .. err)
-	end
+	local c, err = cdr.new(a)
+	local c = check("error parsing cdr file", cdr.new(a))
 
-	local found = false
-	local lineno = 0
-	for line in f:lines() do
-		lineno = lineno + 1
-	end
-	fail_if(lineno ~= records, string.format("expected %s CDR(s) but found %s", records, lineno))
+	fail_if(c:len() ~= records, string.format("expected %s cdr(s) but found %s", records, c:len()))
 end
 
 function do_call(scenario, key)

Modified: asterisk/trunk/tests/cdr/blind-transfer-accountcode/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/blind-transfer-accountcode/test.lua?view=diff&rev=796&r1=795&r2=796
==============================================================================
--- asterisk/trunk/tests/cdr/blind-transfer-accountcode/test.lua (original)
+++ asterisk/trunk/tests/cdr/blind-transfer-accountcode/test.lua Wed Sep 29 10:41:49 2010
@@ -1,3 +1,5 @@
+require "cdr"
+
 have_error = false
 
 function check_error(a)
@@ -50,21 +52,11 @@
 	return res, err
 end
 
-function check_cdr(a, end_line, value)
-	local cdr_path = a:path("/var/log/asterisk/cdr-csv/Master.csv")
-	local f, err = io.open(cdr_path, "r")
-	if not f then
-		error("error opening cdr file (" .. cdr_path .. "): " .. err)
-	end
+function check_cdr_accountcode(a, record, accountcode)
+	local c = check("error parsing cdr file", cdr.new(a))
 
-	local line
-	for i = 1, end_line do
-		line = f:read("*l")
-		if not line then
-			error("error reading lines from cdr file (" .. cdr_path .. ")")
-		end
-	end
-	fail_if(not line:find(value), "'" .. value .. "' not found in line " .. end_line .. " of cdr file (" .. cdr_path .. "):\n" .. line)
+	fail_if(not c[record], string.format("expected accountcode '%s' in record %s, but file only has %s record(s)", accountcode, record, c:len()))
+	fail_if(c[record]["accountcode"] ~= accountcode, string.format("expected accountcode '%s' in record %s, but found '%s'", accountcode, record, tostring(c[record]["accountcode"])))
 end
 
 -- This function will execute the three sipp scenarios using the inf file
@@ -97,7 +89,7 @@
 	proc.perror(a:term_or_kill())
 
 	-- examine the CDR records generated to make sure account code is present
-	check_cdr(a, 2, accountcode)
+	check_cdr_accountcode(a, 2, accountcode)
 end
 
 -- test dialing a peer without an account code set.  The resulting account code

Modified: asterisk/trunk/tests/cdr/originate-cdr-disposition/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/originate-cdr-disposition/test.lua?view=diff&rev=796&r1=795&r2=796
==============================================================================
--- asterisk/trunk/tests/cdr/originate-cdr-disposition/test.lua (original)
+++ asterisk/trunk/tests/cdr/originate-cdr-disposition/test.lua Wed Sep 29 10:41:49 2010
@@ -1,10 +1,5 @@
 
-function check(msg, r, err)
-	if not r then
-		error(msg .. ": " .. err)
-	end
-	return r
-end
+require "cdr"
 
 function mcheck(msg, r, err)
 	check(msg, r, err)
@@ -53,38 +48,17 @@
 
 function check_cdr(a, record, disposition)
 	local cdr_path = a:path("/var/log/asterisk/cdr-csv/Master.csv")
-	local f, err = io.open(cdr_path, "r")
-	if not f then
-		error("error opening cdr file (" .. cdr_path .. "): " .. err)
-	end
+	local c = check("error parsing cdr file", cdr.new(a))
 
-	local found = false
-	local lineno = 0
-	for line in f:lines() do
-		lineno = lineno + 1
-
-		if lineno == record then
-			fail_if(not line:find(string.format('"%s"', disposition)), string.format("did not find disposition '%s' on line %s of cdr:\n%s", disposition, lineno, line))
-			found = true
-			break
-		end
-	end
-	fail_if(not found, string.format("expected disposition '%s' on line %s of cdr, but line %s does not exist in the file", disposition, record, record))
+	fail_if(not c[record], string.format("expected disposition '%s' in record %s, but file only has %s record(s)", disposition, record, c:len()))
+	fail_if(c[record]["disposition"] ~= disposition, string.format("expected disposition '%s' in record %s, but found '%s'", disposition, record, tostring(c[record]["disposition"])))
 end
 
 function check_for_n_cdrs(a, records)
-	local cdr_path = a:path("/var/log/asterisk/cdr-csv/Master.csv")
-	local f, err = io.open(cdr_path, "r")
-	if not f then
-		error("error opening cdr file (" .. cdr_path .. "): " .. err)
-	end
+	local c, err = cdr.new(a)
+	local c = check("error parsing cdr file", cdr.new(a))
 
-	local found = false
-	local lineno = 0
-	for line in f:lines() do
-		lineno = lineno + 1
-	end
-	fail_if(lineno ~= records, string.format("expected %s CDR(s) but found %s", records, lineno))
+	fail_if(c:len() ~= records, string.format("expected %s CDR(s) but found %s", records, c:len()))
 end
 
 function do_originate(a, scenario, record, disposition, timeout, exten)




More information about the asterisk-commits mailing list