diff options
author | Daniel Pittman <daniel@puppetlabs.com> | 2011-05-04 10:30:52 -0700 |
---|---|---|
committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-05-04 12:28:25 -0700 |
commit | a4e735e133898a376747491d5bbc1ca5692ac122 (patch) | |
tree | 1d479a95d91dbfb2cc38f80d8f76140ebbc53a99 /spec | |
parent | d203853bc8b40732c2ba88a4e5396f00a1e3a4ec (diff) | |
download | puppet-a4e735e133898a376747491d5bbc1ca5692ac122.tar.gz puppet-a4e735e133898a376747491d5bbc1ca5692ac122.tar.xz puppet-a4e735e133898a376747491d5bbc1ca5692ac122.zip |
(#7353) Add 'console' format to FormatHandler
This adds a console rendering format to the Network FormatHandler subsystem;
it provides the same human-friendly textual rendering as the Faces application
did, except it uses JSON rather than PP as the fall-back rendering mode.
This paves the path for unification of all formatting into the same subsystem,
rather than the half-measures we used to have.
Reviewed-By: Jacob Helwig <jacob@puppetlabs.com>
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/unit/network/formats_spec.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/unit/network/formats_spec.rb b/spec/unit/network/formats_spec.rb index 72d355192..62c2dbb9d 100755 --- a/spec/unit/network/formats_spec.rb +++ b/spec/unit/network/formats_spec.rb @@ -330,4 +330,66 @@ describe "Puppet Network Format" do end end end + + describe ":console format" do + subject { Puppet::Network::FormatHandler.format(:console) } + it { should be_an_instance_of Puppet::Network::Format } + let :json do Puppet::Network::FormatHandler.format(:pson) end + + [:intern, :intern_multiple].each do |method| + it "should not implement #{method}" do + expect { subject.send(method, String, 'blah') }.to raise_error NotImplementedError + end + end + + ["hello", 1, 1.0].each do |input| + it "should just return a #{input.inspect}" do + subject.render(input).should == input + end + end + + [[1, 2], ["one"], [{ 1 => 1 }]].each do |input| + it "should render #{input.inspect} as JSON" do + subject.render(input).should == json.render(input).chomp + end + end + + it "should render a non-trivially-keyed Hash as JSON" do + hash = { [1,2] => 3, [2,3] => 5, [3,4] => 7 } + subject.render(hash).should == json.render(hash).chomp + end + + it "should render a {String,Numeric}-keyed Hash into a table" do + object = Object.new + hash = { "one" => 1, "two" => [], "three" => {}, "four" => object, + 5 => 5, 6.0 => 6 } + + # Gotta love ASCII-betical sort order. Hope your objects are better + # structured for display than my test one is. --daniel 2011-04-18 + subject.render(hash).should == <<EOT +5 5 +6.0 6 +four #{json.render(object).chomp} +one 1 +three {} +two [] +EOT + end + + it "should render a hash nicely with a multi-line value" do + pending "Moving to PSON rather than PP makes this unsupportable." + hash = { + "number" => { "1" => '1' * 40, "2" => '2' * 40, '3' => '3' * 40 }, + "text" => { "a" => 'a' * 40, 'b' => 'b' * 40, 'c' => 'c' * 40 } + } + subject.render(hash).should == <<EOT +number {"1"=>"1111111111111111111111111111111111111111", + "2"=>"2222222222222222222222222222222222222222", + "3"=>"3333333333333333333333333333333333333333"} +text {"a"=>"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "b"=>"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "c"=>"cccccccccccccccccccccccccccccccccccccccc"} +EOT + end + end end |