summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorPieter van de Bruggen <pieter@puppetlabs.com>2011-03-24 18:55:32 -0700
committerPieter van de Bruggen <pieter@puppetlabs.com>2011-03-25 08:59:08 -0700
commit6aea116701b8e03558ef7a5a15766b267af14281 (patch)
tree1ca02494756c402321e84e9df2f327beb0b78bcb /spec/unit
parent1af9bb232ed73f16789f465e89a0d498c39e1b78 (diff)
downloadpuppet-6aea116701b8e03558ef7a5a15766b267af14281.tar.gz
puppet-6aea116701b8e03558ef7a5a15766b267af14281.tar.xz
puppet-6aea116701b8e03558ef7a5a15766b267af14281.zip
(#6770) Add support for version :latest.
Specifying a version of `:latest` will find the most recent version of the named interface installed in your RUBYLIB, and attempt to load that. This is unlikely to provide a stable dependency in the future, so should be used sparingly, acknowledging the dangers. Reviewed-By: Daniel Pittman
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/application/interface_base_spec.rb14
-rw-r--r--spec/unit/interface/interface_collection_spec.rb46
-rwxr-xr-xspec/unit/interface_spec.rb4
3 files changed, 63 insertions, 1 deletions
diff --git a/spec/unit/application/interface_base_spec.rb b/spec/unit/application/interface_base_spec.rb
index 15d465559..d82325bfd 100644
--- a/spec/unit/application/interface_base_spec.rb
+++ b/spec/unit/application/interface_base_spec.rb
@@ -4,7 +4,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
require 'puppet/application/interface_base'
describe Puppet::Application::InterfaceBase do
- base_interface = Puppet::Interface[:basetest, '0.0.1']
+ before :all do
+ @dir = Dir.mktmpdir
+ $LOAD_PATH.push(@dir)
+ FileUtils.mkdir_p(File.join @dir, 'puppet', 'interface', 'v0.0.1')
+ FileUtils.touch(File.join @dir, 'puppet', 'interface', 'v0.0.1', 'basetest.rb')
+ end
+
+ after :all do
+ FileUtils.remove_entry_secure @dir
+ $LOAD_PATH.pop
+ end
+
+ base_interface = Puppet::Interface.define(:basetest, '0.0.1')
class Puppet::Application::InterfaceBase::Basetest < Puppet::Application::InterfaceBase
end
diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb
index a943c2ec2..3e4b9d624 100644
--- a/spec/unit/interface/interface_collection_spec.rb
+++ b/spec/unit/interface/interface_collection_spec.rb
@@ -63,6 +63,32 @@ describe Puppet::Interface::InterfaceCollection do
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
@@ -125,6 +151,17 @@ describe Puppet::Interface::InterfaceCollection 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
@@ -133,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
diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb
index 060a71fb8..cf7d209da 100755
--- a/spec/unit/interface_spec.rb
+++ b/spec/unit/interface_spec.rb
@@ -36,6 +36,10 @@ describe Puppet::Interface do
proc { Puppet::Interface.new(:no_version) }.should raise_error(ArgumentError)
end
+ it "should require a valid version number" do
+ proc { Puppet::Interface.new(:bad_version, 'Rasins') }.should raise_error(ArgumentError)
+ end
+
it "should instance-eval any provided block" do
face = Puppet::Interface.new(:interface_test_block,'0.0.1') do
action(:something) do