4 require File.dirname(__FILE__) + "/../../../../../plugins/mcollective/aggregate/summary.rb"
9 describe "#startup_hook" do
10 it "should set the correct result hash" do
11 result = Summary.new(:test, [], "%d", :test_action)
12 result.result.should == {:value => {}, :type => :collection, :output => :test}
13 result.aggregate_format.should == "%d"
16 it "should set a defauly aggregate_format if one isn't defined" do
17 result = Summary.new(:test, [], nil, :test_action)
18 result.aggregate_format.should == :calculate
22 describe "#process_result" do
23 it "should add the value to the result hash" do
24 sum = Summary.new(:test, [], "%d", :test_action)
25 sum.process_result(:foo, {:test => :foo})
26 sum.result[:value].should == {:foo => 1}
29 it "should add the reply values to the result hash if value is an array" do
30 sum = Summary.new(:test, [], "%d", :test_action)
31 sum.process_result([:foo, :foo, :bar], {:test => [:foo, :foo, :bar]})
32 sum.result[:value].should == {:foo => 2, :bar => 1}
36 describe "#summarize" do
37 it "should calculate an attractive format" do
38 sum = Summary.new(:test, [], nil, :test_action)
39 sum.result[:value] = {"shrt" => 1, "long key" => 1}
40 sum.summarize.aggregate_format.should == "%8s = %s"
43 it "should calculate an attractive format when result type is not a string" do
44 sum1 = Summary.new(:test, [], nil, :test_action)
45 sum1.result[:value] = {true => 4, false => 5}
46 sum1.summarize.aggregate_format.should == "%5s = %s"
48 sum2 = Summary.new(:test, [], nil, :test_action)
49 sum2.result[:value] = {1 => 1, 10 => 2}
50 sum2.summarize.aggregate_format.should == "%2s = %s"