Update mcollective.init according to OSCI-855
[packages/precise/mcollective.git] / spec / unit / plugins / mcollective / aggregate / summary_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4 require File.dirname(__FILE__) + "/../../../../../plugins/mcollective/aggregate/summary.rb"
5
6 module MCollective
7   class Aggregate
8     describe Summary do
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"
14         end
15
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
19         end
20       end
21
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}
27         end
28
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}
33         end
34       end
35
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"
41         end
42
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"
47
48           sum2 = Summary.new(:test, [], nil, :test_action)
49           sum2.result[:value] = {1 => 1, 10 => 2}
50           sum2.summarize.aggregate_format.should == "%2s = %s"
51         end
52       end
53     end
54   end
55 end