blob: c7fc48cb9e7a8f92bae293579d878fb73841b810 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
require 'spec_helper'
require 'puppet/util/profiler'
describe Puppet::Util::Profiler do
let(:profiler) { TestProfiler.new() }
it "supports adding profilers" do
subject.add_profiler(profiler)
subject.current[0].should == profiler
end
it "supports removing profilers" do
subject.add_profiler(profiler)
subject.remove_profiler(profiler)
subject.current.length.should == 0
end
it "supports clearing profiler list" do
subject.add_profiler(profiler)
subject.clear
subject.current.length.should == 0
end
it "supports profiling" do
subject.add_profiler(profiler)
subject.profile("hi", ["mymetric"]) {}
profiler.context[:metric_id].should == ["mymetric"]
profiler.context[:description].should == "hi"
profiler.description.should == "hi"
end
it "supports profiling without a metric id" do
subject.add_profiler(profiler)
subject.profile("hi") {}
profiler.context[:metric_id].should == nil
profiler.context[:description].should == "hi"
profiler.description.should == "hi"
end
class TestProfiler
attr_accessor :context, :metric, :description
def start(description, metric_id)
{:metric_id => metric_id,
:description => description}
end
def finish(context, description, metric_id)
@context = context
@metric_id = metric_id
@description = description
end
end
end
|