diff options
| author | Pieter van de Bruggen <pieter@puppetlabs.com> | 2011-03-25 08:59:29 -0700 |
|---|---|---|
| committer | Pieter van de Bruggen <pieter@puppetlabs.com> | 2011-03-25 08:59:29 -0700 |
| commit | 4c320cc482a33892a688d3a5072081e6d63a8310 (patch) | |
| tree | 1ca02494756c402321e84e9df2f327beb0b78bcb /spec/unit/interface | |
| parent | 53b0656048c3227048bdc317c5e917ad0c39e850 (diff) | |
| parent | 6aea116701b8e03558ef7a5a15766b267af14281 (diff) | |
Merge branch 'tickets/master/6770'
Diffstat (limited to 'spec/unit/interface')
| -rw-r--r-- | spec/unit/interface/action_builder_spec.rb | 2 | ||||
| -rw-r--r-- | spec/unit/interface/action_spec.rb | 4 | ||||
| -rw-r--r-- | spec/unit/interface/indirector_spec.rb | 4 | ||||
| -rw-r--r-- | spec/unit/interface/interface_collection_spec.rb | 150 |
4 files changed, 154 insertions, 6 deletions
diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb index 2c2f3b14c..27e817fe9 100644 --- a/spec/unit/interface/action_builder_spec.rb +++ b/spec/unit/interface/action_builder_spec.rb @@ -13,7 +13,7 @@ describe Puppet::Interface::ActionBuilder do end it "should define a method on the interface which invokes the action" do - interface = Puppet::Interface.new(:action_builder_test_interface, :version => '0.0.1') + interface = Puppet::Interface.new(:action_builder_test_interface, '0.0.1') action = Puppet::Interface::ActionBuilder.build(interface, :foo) do invoke do "invoked the method" diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb index 246ae9622..292caabb9 100644 --- a/spec/unit/interface/action_spec.rb +++ b/spec/unit/interface/action_spec.rb @@ -24,7 +24,7 @@ describe Puppet::Interface::Action do describe "when invoking" do it "should be able to call other actions on the same object" do - interface = Puppet::Interface.new(:my_interface, :version => '0.0.1') do + interface = Puppet::Interface.new(:my_interface, '0.0.1') do action(:foo) do invoke { 25 } end @@ -56,7 +56,7 @@ describe Puppet::Interface::Action do end end - interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, :version => '0.0.1') do + interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, '0.0.1') do action(:baz) do invoke { "the value of foo in baz is '#{foo}'" } end diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb index b14058eca..4b2beaefc 100644 --- a/spec/unit/interface/indirector_spec.rb +++ b/spec/unit/interface/indirector_spec.rb @@ -5,7 +5,7 @@ require 'puppet/interface/indirector' describe Puppet::Interface::Indirector do before do - @instance = Puppet::Interface::Indirector.new(:test, :version => '0.0.1') + @instance = Puppet::Interface::Indirector.new(:test, '0.0.1') @indirection = stub 'indirection', :name => :stub_indirection @@ -24,7 +24,7 @@ describe Puppet::Interface::Indirector do it "should be able to determine its indirection" do # Loading actions here an get, um, complicated Puppet::Interface.stubs(:load_actions) - Puppet::Interface::Indirector.new(:catalog, :version => '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection) + Puppet::Interface::Indirector.new(:catalog, '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection) end end diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb index 193d31b1e..3e4b9d624 100644 --- a/spec/unit/interface/interface_collection_spec.rb +++ b/spec/unit/interface/interface_collection_spec.rb @@ -1,6 +1,7 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'tmpdir' describe Puppet::Interface::InterfaceCollection do before :all do @@ -18,11 +19,149 @@ describe Puppet::Interface::InterfaceCollection do describe "::interfaces" do end + describe "::versions" do + before :each do + @dir = Dir.mktmpdir + @lib = FileUtils.mkdir_p(File.join @dir, 'puppet', 'interface') + $LOAD_PATH.push(@dir) + end + + after :each do + FileUtils.remove_entry_secure @dir + $LOAD_PATH.pop + end + + it "should return an empty array when no versions are loadable" do + subject.versions(:fozzie).should == [] + end + + it "should return versions loadable as puppet/interface/v{version}/{name}" do + FileUtils.mkdir_p(File.join @lib, 'v1.0.0') + FileUtils.touch(File.join @lib, 'v1.0.0', 'fozzie.rb') + subject.versions(:fozzie).should == ['1.0.0'] + end + + it "should an ordered list of all versions loadable as puppet/interface/v{version}/{name}" do + %w[ 1.2.1rc2 1.2.1beta1 1.2.1rc1 1.2.1 1.2.2 ].each do |version| + FileUtils.mkdir_p(File.join @lib, "v#{version}") + FileUtils.touch(File.join @lib, "v#{version}", 'fozzie.rb') + end + subject.versions(:fozzie).should == %w[ 1.2.1beta1 1.2.1rc1 1.2.1rc2 1.2.1 1.2.2 ] + end + + it "should not return a version for an empty puppet/interface/v{version}/{name}" do + FileUtils.mkdir_p(File.join @lib, 'v1.0.0', 'fozzie') + subject.versions(:fozzie).should == [] + end + + it "should an ordered list of all versions loadable as puppet/interface/v{version}/{name}/*.rb" do + %w[ 1.2.1rc2 1.2.1beta1 1.2.1rc1 1.2.1 1.2.2 ].each do |version| + FileUtils.mkdir_p(File.join @lib, "v#{version}", "fozzie") + FileUtils.touch(File.join @lib, "v#{version}", 'fozzie', 'action.rb') + end + subject.versions(:fozzie).should == %w[ 1.2.1beta1 1.2.1rc1 1.2.1rc2 1.2.1 1.2.2 ] + end + end + + describe "::validate_version" do + it 'should permit three number versions' do + subject.validate_version('10.10.10').should == true + end + + it 'should permit versions with appended descriptions' do + subject.validate_version('10.10.10beta').should == true + end + + it 'should not permit versions with more than three numbers' do + subject.validate_version('1.2.3.4').should == false + end + + it 'should not permit versions with only two numbers' do + subject.validate_version('10.10').should == false + end + + it 'should not permit versions with only one number' do + subject.validate_version('123').should == false + end + + it 'should not permit versions with text in any position but at the end' do + subject.validate_version('v1.1.1').should == false + end + end + + describe "::compare_versions" do + # (a <=> b) should be: + # -1 if a < b + # 0 if a == b + # 1 if a > b + it 'should sort major version numbers numerically' do + subject.compare_versions('1.0.0', '2.0.0').should == -1 + subject.compare_versions('2.0.0', '1.1.1').should == 1 + subject.compare_versions('2.0.0', '10.0.0').should == -1 + end + + it 'should sort minor version numbers numerically' do + subject.compare_versions('0.1.0', '0.2.0').should == -1 + subject.compare_versions('0.2.0', '0.1.1').should == 1 + subject.compare_versions('0.2.0', '0.10.0').should == -1 + end + + it 'should sort tiny version numbers numerically' do + subject.compare_versions('0.0.1', '0.0.2').should == -1 + subject.compare_versions('0.0.2', '0.0.1').should == 1 + subject.compare_versions('0.0.2', '0.0.10').should == -1 + end + + it 'should sort major version before minor version' do + subject.compare_versions('1.1.0', '1.2.0').should == -1 + subject.compare_versions('1.2.0', '1.1.1').should == 1 + subject.compare_versions('1.2.0', '1.10.0').should == -1 + + subject.compare_versions('1.1.0', '2.2.0').should == -1 + subject.compare_versions('2.2.0', '1.1.1').should == 1 + subject.compare_versions('2.2.0', '1.10.0').should == 1 + end + + it 'should sort minor version before tiny version' do + subject.compare_versions('0.1.1', '0.1.2').should == -1 + subject.compare_versions('0.1.2', '0.1.1').should == 1 + subject.compare_versions('0.1.2', '0.1.10').should == -1 + + subject.compare_versions('0.1.1', '0.2.2').should == -1 + subject.compare_versions('0.2.2', '0.1.1').should == 1 + subject.compare_versions('0.2.2', '0.1.10').should == 1 + end + + it 'should sort appended strings asciibetically' do + subject.compare_versions('0.0.0a', '0.0.0b').should == -1 + subject.compare_versions('0.0.0beta1', '0.0.0beta2').should == -1 + subject.compare_versions('0.0.0beta1', '0.0.0rc1').should == -1 + subject.compare_versions('0.0.0beta1', '0.0.0alpha1').should == 1 + subject.compare_versions('0.0.0beta1', '0.0.0beta1').should == 0 + end + + it "should sort appended strings before 'whole' versions" do + subject.compare_versions('0.0.1a', '0.0.1').should == -1 + subject.compare_versions('0.0.1', '0.0.1beta').should == 1 + end + end + describe "::[]" do before :each do subject.instance_variable_get("@interfaces")[:foo]['0.0.1'] = 10 end + before :each do + @dir = Dir.mktmpdir + @lib = FileUtils.mkdir_p(File.join @dir, 'puppet', 'interface') + $LOAD_PATH.push(@dir) + end + + after :each do + FileUtils.remove_entry_secure @dir + $LOAD_PATH.pop + end + it "should return the interface with the given name" do subject["foo", '0.0.1'].should == 10 end @@ -31,6 +170,15 @@ describe Puppet::Interface::InterfaceCollection do subject.expects(:require).with('puppet/interface/v0.0.1/bar') subject["bar", '0.0.1'] end + + it "should attempt to load the interface with the greatest version for specified version :latest" do + %w[ 1.2.1 1.2.2 ].each do |version| + FileUtils.mkdir_p(File.join @lib, "v#{version}") + FileUtils.touch(File.join @lib, "v#{version}", 'fozzie.rb') + end + subject.expects(:require).with('puppet/interface/v1.2.2/fozzie') + subject['fozzie', :latest] + end end describe "::interface?" do @@ -67,7 +215,7 @@ describe Puppet::Interface::InterfaceCollection do describe "::register" do it "should store the interface by name" do - interface = Puppet::Interface.new(:my_interface, :version => '0.0.1') + interface = Puppet::Interface.new(:my_interface, '0.0.1') subject.register(interface) subject.instance_variable_get("@interfaces").should == {:my_interface => {'0.0.1' => interface}} end |
