summaryrefslogtreecommitdiff
path: root/test/other/metrics.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-10-22 22:27:20 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-10-22 22:27:20 +0000
commitf7328804d00d8a82d7ab3a955ff579ff956ef3d0 (patch)
tree7a6d5119dea6a6309675120fd99f5cc023ad644a /test/other/metrics.rb
parent8fe558cca075ab85619a73f4a80408de58810ef7 (diff)
downloadpuppet-f7328804d00d8a82d7ab3a955ff579ff956ef3d0.tar.gz
Getting rid of the tc_ prefix to test cases
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@724 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/other/metrics.rb')
-rw-r--r--test/other/metrics.rb92
1 files changed, 92 insertions, 0 deletions
diff --git a/test/other/metrics.rb b/test/other/metrics.rb
new file mode 100644
index 000000000..dbae3cf54
--- /dev/null
+++ b/test/other/metrics.rb
@@ -0,0 +1,92 @@
+if __FILE__ == $0
+ $:.unshift '..'
+ $:.unshift '../../lib'
+ $puppetbase = "../.."
+end
+
+require 'puppet/metric'
+require 'puppet'
+require 'puppet/type'
+require 'test/unit'
+
+$haverrd = true
+begin
+ require 'RRD'
+rescue LoadError
+ $haverrd = false
+end
+
+if $haverrd
+ class TestMetric < Test::Unit::TestCase
+
+ def gendata
+ totalmax = 1000
+ changemax = 1000
+ eventmax = 10
+ maxdiff = 10
+
+ types = [Puppet::Type::PFile, Puppet::Type::Package, Puppet::Type::Service]
+ data = [:total, :managed, :outofsync, :changed, :totalchanges]
+ events = [:file_changed, :package_installed, :service_started]
+
+ # if this is the first set of data points...
+ typedata = Hash.new { |typehash,type|
+ typehash[type] = Hash.new(0)
+ }
+ eventdata = Hash.new(0)
+ types.each { |type|
+ name = type.name
+ typedata[type] = {}
+ typedata[type][:total] = rand(totalmax)
+ typedata[type][:managed] = rand(typedata[type][:total])
+ typedata[type][:outofsync] = rand(typedata[type][:managed])
+ typedata[type][:changed] = rand(typedata[type][:outofsync])
+ typedata[type][:totalchanges] = rand(changemax)
+ }
+
+ events.each { |event|
+ eventdata[event] = rand(eventmax)
+ }
+
+ return [typedata,eventdata]
+ end
+
+ def setup
+ Puppet[:rrddir] = File.join(Puppet[:puppetvar], "rrdtesting")
+ Puppet[:rrdgraph] = true
+ Puppet[:loglevel] = :debug if __FILE__ == $0
+ end
+
+ def teardown
+ system("rm -rf %s" % Puppet[:rrddir])
+ end
+
+ def test_fakedata
+ assert_nothing_raised { Puppet::Metric.init }
+ time = Time.now.to_i
+ start = time
+ 10.times {
+ assert_nothing_raised { Puppet::Metric.load(gendata) }
+ assert_nothing_raised { Puppet::Metric.tally }
+ assert_nothing_raised { Puppet::Metric.store(time) }
+ assert_nothing_raised { Puppet::Metric.clear }
+ time += 300
+ }
+ assert_nothing_raised { Puppet::Metric.load(gendata) }
+ assert_nothing_raised { Puppet::Metric.tally }
+ assert_nothing_raised { Puppet::Metric.store(time) }
+ assert_nothing_raised { Puppet::Metric.graph([start,time]) }
+
+ File.open(File.join(Puppet[:rrddir],"index.html"),"w") { |of|
+ of.puts "<html><body>"
+ Puppet::Metric.each { |metric|
+ of.puts "<img src=%s.png><br>" % metric.name
+ }
+ }
+ end
+ end
+else
+ $stderr.puts "Missing RRD library -- skipping metric tests"
+end
+
+# $Id$