Skip to content

Commit

Permalink
Finished up first set of unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danlynn committed Feb 13, 2012
1 parent 2622b9d commit e280109
Show file tree
Hide file tree
Showing 5 changed files with 22,270 additions and 11 deletions.
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

require 'rake'
require 'rake/packagetask'
# require 'rake/testtask'
require 'rake/testtask'
# require 'rake/rdoctask'
require 'pathname'

Expand Down Expand Up @@ -44,3 +44,10 @@ Rake::PackageTask.new("ClamAV-Scan_Report", "1.1.0") do |p|
p.package_files.include("clamav.rb")
p.package_files.include("docs/**/*")
end


Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/*test.rb']
t.verbose = true
end
59 changes: 59 additions & 0 deletions test/clam_av_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require "test/unit"
require 'yaml'
require 'erb'
require 'fileutils'
require 'pathname'
require 'etc' # needed by user home dir determination in config/clamav.yml files

class ClamAvTest < Test::Unit::TestCase

# Called before every test method runs. Can be used
# to set up fixture information.
def setup
FileUtils.cd(Pathname(__FILE__).parent.parent.realpath) # enable relative paths (even in require)
end

# Called after every test method runs. Can be used to tear
# down fixture information.

def teardown
# Do nothing
end

def test_clam_bin_dir
$config = YAML.load(ERB.new(IO.read('config/clamav.yml')).result(binding))
unless $config['clam_bin_dir']
fail("Specified config.yml clam_bin_dir is empty. Only tests can be run without specifying the clam_bin_dir.")
end
end

def test_clamav_installed
$config = YAML.load(ERB.new(IO.read('config/clamav.yml')).result(binding))
unless File.exists?($config['clam_bin_dir'])
fail("Specified config.yml clam_bin_dir does not exist. Does clamav needs to be installed?")
end
end

def run_report_in_test_dir(dir_name)
`ruby clamav.rb --config test/#{dir_name}/config/clamav.yml`
actual = File.read('clamav.html')
expected = File.read("test/#{dir_name}/clamav.expected_output.html")
unless actual == expected
`opendiff test/#{dir_name}/clamav.expected_output.html clamav.html &` rescue nil
fail("test/#{dir_name} generated a clamav.html which failed to match test/#{dir_name}/clamav.expected_output.html")
end
end

def test_report1
run_report_in_test_dir('test1')
end

def test_report2
run_report_in_test_dir('test2')
end

def test_report3
run_report_in_test_dir('test3')
end

end
10 changes: 5 additions & 5 deletions test/test1/clamav.expected_output.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
$.plot($("#placeholder"), [
{
label: "infections count changes",
data: [[1256111421000, 0], [1256284251000, 0], [1256370680000, 0], [1256456686000, 0], [1256543398000, 0], [1256629781000, 0], [1256716451000, 0], [1256802714000, 0], [1256889249000, 0], [1256975386000, 2], [1257062348000, 0], [1257070054000, 0], [1257151868000, 0], [1257252752000, 0], [1257324802000, 1], [1257411095000, -1], [1257497568000, 0], [1257583982000, 0], [1257670303000, 0], [1257756700000, 0], [1257843458000, 0], [1257930385000, 0], [1258015824000, 0], [1258102386000, 0], [1258188761000, 0], [1258275405000, 0], [1258361610000, 0], [1258447760000, 0], [1258534174000, 2], [1258620810000, -2]],
data: [[1256111421000,0],[1256284251000,0],[1256370680000,0],[1256456686000,0],[1256543398000,0],[1256629781000,0],[1256716451000,0],[1256802714000,0],[1256889249000,0],[1256975386000,2],[1257062348000,0],[1257070054000,0],[1257151868000,0],[1257252752000,0],[1257324802000,1],[1257411095000,-1],[1257497568000,0],[1257583982000,0],[1257670303000,0],[1257756700000,0],[1257843458000,0],[1257930385000,0],[1258015824000,0],[1258102386000,0],[1258188761000,0],[1258275405000,0],[1258361610000,0],[1258447760000,0],[1258534174000,2],[1258620810000,-2]],
lines: { show: true, fill: true }
},
{
label: "known viruses count changes",
data: [[1256111421000, 0], [1256284251000, 3391], [1256370680000, 3], [1256456686000, 23], [1256543398000, 47], [1256629781000, 219], [1256716451000, 447], [1256802714000, 3367], [1256889249000, 348], [1256975386000, 58], [1257062348000, 10], [1257070054000, 0], [1257151868000, 7], [1257252752000, 0], [1257324802000, 1615], [1257411095000, 3783], [1257497568000, 80], [1257583982000, 5], [1257670303000, 9], [1257756700000, 10], [1257843458000, 878], [1257930385000, 940], [1258015824000, 125], [1258102386000, 1195], [1258188761000, 11], [1258275405000, 5], [1258361610000, 4], [1258447760000, 6], [1258534174000, 2528], [1258620810000, 103]],
data: [[1256111421000,0],[1256284251000,3391],[1256370680000,3],[1256456686000,23],[1256543398000,47],[1256629781000,219],[1256716451000,447],[1256802714000,3367],[1256889249000,348],[1256975386000,58],[1257062348000,10],[1257070054000,0],[1257151868000,7],[1257252752000,0],[1257324802000,1615],[1257411095000,3783],[1257497568000,80],[1257583982000,5],[1257670303000,9],[1257756700000,10],[1257843458000,878],[1257930385000,940],[1258015824000,125],[1258102386000,1195],[1258188761000,11],[1258275405000,5],[1258361610000,4],[1258447760000,6],[1258534174000,2528],[1258620810000,103]],
// bars: { barWidth: 43200000, align: "center", show: true },
bars: { barWidth: 41868080.6451613, align: "center", show: true },
bars: { barWidth: 41868080.645161286, align: "center", show: true },
yaxis: 2
}
], {
Expand Down Expand Up @@ -149,8 +149,8 @@ <h1>ClamAV Scan Report</h1>
<div id="tabs-2">
<table class='line'><tr><td><div class='label'>directories scanned:</div></td><td><div class='field'>84596</div></td></tr></table>
<table class='line'><tr><td><div class='label'>files scanned:</div></td><td><span class='changed'><div class='field'>383843</div><div class='comment'>&nbsp;&nbsp;(prev 383719)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>data scanned:</div></td><td><span class='changed'><div class='field'>30.7 GB</div><div class='comment'>&nbsp;&nbsp;(prev 30.68 GB)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>data read:</div></td><td><span class='changed'><div class='field'>36.89 GB</div><div class='comment'>&nbsp;&nbsp;(prev 36.85 GB)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>data scanned:</div></td><td><span class='changed'><div class='field'>31 GB</div><div class='comment'>&nbsp;&nbsp;(prev 31 GB)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>data read:</div></td><td><span class='changed'><div class='field'>37 GB</div><div class='comment'>&nbsp;&nbsp;(prev 37 GB)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>Excluded files:</div></td><td><div class='field'>jar, war, ear, sit, sitx, dmg, tgz, gz, m4a, m4b, m4p, m4v, mp3, mp4, avi, vhd, hdd, sav</div></td></tr></table>
</div>
<div id="tabs-3">
Expand Down
10 changes: 5 additions & 5 deletions test/test2/clamav.expected_output.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
$.plot($("#placeholder"), [
{
label: "infections count changes",
data: [[1257756700000, 0], [1257843458000, 0], [1257930385000, 0], [1258015824000, 0], [1258102386000, 0], [1258188761000, 0], [1258275405000, 0], [1258361610000, 0], [1258447760000, 0], [1258534174000, 2], [1258620810000, -2], [1258707210000, 0], [1258793301000, 0], [1258879928000, 0], [1258966417000, 2], [1259053034000, 0], [1259138863000, 0], [1259225673000, 0], [1259312373000, 0], [1259398686000, 0], [1259485124000, 0], [1259570858000, 0], [1259657309000, 0], [1259743861000, 0], [1259831337000, 0], [1259916898000, 0], [1260003539000, 0], [1260090660000, 0], [1260177018000, 0], [1260262464000, 5]],
data: [[1257756700000,0],[1257843458000,0],[1257930385000,0],[1258015824000,0],[1258102386000,0],[1258188761000,0],[1258275405000,0],[1258361610000,0],[1258447760000,0],[1258534174000,2],[1258620810000,-2],[1258707210000,0],[1258793301000,0],[1258879928000,0],[1258966417000,2],[1259053034000,0],[1259138863000,0],[1259225673000,0],[1259312373000,0],[1259398686000,0],[1259485124000,0],[1259570858000,0],[1259657309000,0],[1259743861000,0],[1259831337000,0],[1259916898000,0],[1260003539000,0],[1260090660000,0],[1260177018000,0],[1260262464000,5]],
lines: { show: true, fill: true }
},
{
label: "known viruses count changes",
data: [[1257756700000, 0], [1257843458000, 878], [1257930385000, 940], [1258015824000, 125], [1258102386000, 1195], [1258188761000, 11], [1258275405000, 5], [1258361610000, 4], [1258447760000, 6], [1258534174000, 2528], [1258620810000, 103], [1258707210000, 1832], [1258793301000, 119], [1258879928000, 14], [1258966417000, 4], [1259053034000, 2879], [1259138863000, 560], [1259225673000, 1088], [1259312373000, 657], [1259398686000, 8], [1259485124000, 496], [1259570858000, 7], [1259657309000, 709], [1259743861000, 72], [1259831337000, 574], [1259916898000, 886], [1260003539000, 5], [1260090660000, 0], [1260177018000, 28], [1260262464000, 2314]],
data: [[1257756700000,0],[1257843458000,878],[1257930385000,940],[1258015824000,125],[1258102386000,1195],[1258188761000,11],[1258275405000,5],[1258361610000,4],[1258447760000,6],[1258534174000,2528],[1258620810000,103],[1258707210000,1832],[1258793301000,119],[1258879928000,14],[1258966417000,4],[1259053034000,2879],[1259138863000,560],[1259225673000,1088],[1259312373000,657],[1259398686000,8],[1259485124000,496],[1259570858000,7],[1259657309000,709],[1259743861000,72],[1259831337000,574],[1259916898000,886],[1260003539000,5],[1260090660000,0],[1260177018000,28],[1260262464000,2314]],
// bars: { barWidth: 43200000, align: "center", show: true },
bars: { barWidth: 41762733.3333333, align: "center", show: true },
bars: { barWidth: 41762733.33333333, align: "center", show: true },
yaxis: 2
}
], {
Expand Down Expand Up @@ -172,8 +172,8 @@ <h1>ClamAV Scan Report</h1>
<div id="tabs-2">
<table class='line'><tr><td><div class='label'>directories scanned:</div></td><td><span class='changed'><div class='field'>86679</div><div class='comment'>&nbsp;&nbsp;(prev 86602)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>files scanned:</div></td><td><span class='changed'><div class='field'>387969</div><div class='comment'>&nbsp;&nbsp;(prev 388131)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>data scanned:</div></td><td><span class='changed'><div class='field'>32.86 GB</div><div class='comment'>&nbsp;&nbsp;(prev 32.81 GB)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>data read:</div></td><td><span class='changed'><div class='field'>39.06 GB</div><div class='comment'>&nbsp;&nbsp;(prev 38.26 GB)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>data scanned:</div></td><td><span class='changed'><div class='field'>33 GB</div><div class='comment'>&nbsp;&nbsp;(prev 33 GB)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>data read:</div></td><td><span class='changed'><div class='field'>39 GB</div><div class='comment'>&nbsp;&nbsp;(prev 38 GB)</div></span></td></tr></table>
<table class='line'><tr><td><div class='label'>Excluded files:</div></td><td><div class='field'>jar, war, ear, sit, sitx, dmg, tgz, gz, m4a, m4b, m4p, m4v, mp3, mp4, avi, vhd, hdd, sav</div></td></tr></table>
</div>
<div id="tabs-3">
Expand Down
Loading

0 comments on commit e280109

Please sign in to comment.