summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorPieter van de Bruggen <pieter@puppetlabs.com>2011-03-25 14:52:48 -0700
committerPieter van de Bruggen <pieter@puppetlabs.com>2011-03-28 18:07:15 -0700
commit4609e203fd47f8159118bb74a8308f9c6aee179f (patch)
treec3feec649a86d9f7bdf15e24053fdf6c2f2b8df6 /spec
parent2ad8c96935ec53c2d98201ad77fd070dc40dadb6 (diff)
downloadpuppet-4609e203fd47f8159118bb74a8308f9c6aee179f.tar.gz
puppet-4609e203fd47f8159118bb74a8308f9c6aee179f.tar.xz
puppet-4609e203fd47f8159118bb74a8308f9c6aee179f.zip
(#6770) Change versioning; adopt :current over :latest.
As per discussion with Luke, versions of an interface are first looked up by requiring 'puppet/interface/{name}', and secondarily looked up by requiring '{name}@{version}/puppet/interface/{name}' if the first failed. A version of `:current` can be used to represent the version living in 'puppet/interface/{name}'. Paired-With: Nick Lewis
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/application/string_base_spec.rb15
-rwxr-xr-xspec/unit/string/string_collection_spec.rb167
-rwxr-xr-xspec/unit/string_spec.rb3
3 files changed, 61 insertions, 124 deletions
diff --git a/spec/unit/application/string_base_spec.rb b/spec/unit/application/string_base_spec.rb
index bc563e11d..86f9c09aa 100755
--- a/spec/unit/application/string_base_spec.rb
+++ b/spec/unit/application/string_base_spec.rb
@@ -2,13 +2,19 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
require 'puppet/application/string_base'
+require 'tmpdir'
+
+class Puppet::Application::StringBase::Basetest < Puppet::Application::StringBase
+end
describe Puppet::Application::StringBase do
before :all do
@dir = Dir.mktmpdir
$LOAD_PATH.push(@dir)
- FileUtils.mkdir_p(File.join @dir, 'puppet', 'string', 'v0.0.1')
- FileUtils.touch(File.join @dir, 'puppet', 'string', 'v0.0.1', 'basetest.rb')
+ FileUtils.mkdir_p(File.join @dir, 'puppet', 'string')
+ File.open(File.join(@dir, 'puppet', 'string', 'basetest.rb'), 'w') do |f|
+ f.puts "Puppet::String.define(:basetest, '0.0.1')"
+ end
end
after :all do
@@ -16,13 +22,8 @@ describe Puppet::Application::StringBase do
$LOAD_PATH.pop
end
- base_string = Puppet::String.define(:basetest, '0.0.1')
- class Puppet::Application::StringBase::Basetest < Puppet::Application::StringBase
- end
-
before do
@app = Puppet::Application::StringBase::Basetest.new
- @app.stubs(:string).returns base_string
@app.stubs(:exit)
@app.stubs(:puts)
Puppet::Util::Log.stubs(:newdestination)
diff --git a/spec/unit/string/string_collection_spec.rb b/spec/unit/string/string_collection_spec.rb
index 46c431f75..63ddf7c5e 100755
--- a/spec/unit/string/string_collection_spec.rb
+++ b/spec/unit/string/string_collection_spec.rb
@@ -5,64 +5,19 @@ require 'tmpdir'
describe Puppet::String::StringCollection do
before :all do
- @strings = subject.instance_variable_get("@strings").dup
+ @strings = subject.instance_variable_get("@strings")
+ @strings_backup = @strings.dup
end
- before :each do
- subject.instance_variable_get("@strings").clear
- end
+ before { @strings.clear }
after :all do
- subject.instance_variable_set("@strings", @strings)
+ subject.instance_variable_set("@strings", @strings_backup)
end
describe "::strings" do
end
- describe "::versions" do
- before :each do
- @dir = Dir.mktmpdir
- @lib = FileUtils.mkdir_p(File.join @dir, 'puppet', 'string')
- $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/string/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/string/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/string/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/string/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
@@ -89,63 +44,6 @@ describe Puppet::String::StringCollection do
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("@strings")[:foo]['0.0.1'] = 10
@@ -167,17 +65,15 @@ describe Puppet::String::StringCollection do
end
it "should attempt to load the string if it isn't found" do
- subject.expects(:require).with('puppet/string/v0.0.1/bar')
+ subject.expects(:require).with('puppet/string/bar')
+ subject.expects(:require).with('bar@0.0.1/puppet/string/bar')
subject["bar", '0.0.1']
end
- it "should attempt to load the string 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/string/v1.2.2/fozzie')
- subject['fozzie', :latest]
+ it "should attempt to load the default string for the specified version :current" do
+ subject.expects(:require).never # except...
+ subject.expects(:require).with('puppet/string/fozzie')
+ subject['fozzie', :current]
end
end
@@ -191,14 +87,25 @@ describe Puppet::String::StringCollection do
end
it "should attempt to require the string if it is not registered" do
- subject.expects(:require).with('puppet/string/v0.0.1/bar')
- subject.string?("bar", '0.0.1')
+ subject.expects(:require).with do |file|
+ @strings[:bar]['0.0.1'] = true
+ file == 'puppet/string/bar'
+ end
+ subject.string?("bar", '0.0.1').should == true
end
it "should return true if requiring the string registered it" do
subject.stubs(:require).with do
subject.instance_variable_get("@strings")[:bar]['0.0.1'] = 20
end
+ end
+
+ it "should require the string by version if the 'current' version isn't it" do
+ subject.expects(:require).with('puppet/string/bar').raises(LoadError)
+ subject.expects(:require).with do |file|
+ @strings[:bar]['0.0.1'] = true
+ file == 'bar@0.0.1/puppet/string/bar'
+ end
subject.string?("bar", '0.0.1').should == true
end
@@ -211,6 +118,34 @@ describe Puppet::String::StringCollection do
subject.stubs(:require).raises(LoadError)
subject.string?("bar", '0.0.1').should == false
end
+
+ it "should register the version loaded by `:current` as `:current`" do
+ subject.expects(:require).with do |file|
+ @strings[:huzzah]['2.0.1'] = :huzzah_string
+ file == 'puppet/string/huzzah'
+ end
+ subject.string?("huzzah", :current)
+ @strings[:huzzah][:current].should == :huzzah_string
+ end
+
+ it "should register the version loaded from `puppet/string/{name}` as `:current`" do
+ subject.expects(:require).with do |file|
+ @strings[:huzzah]['2.0.1'] = :huzzah_string
+ file == 'puppet/string/huzzah'
+ end
+ subject.string?("huzzah", '2.0.1')
+ @strings[:huzzah][:current].should == :huzzah_string
+ end
+
+ it "should not register the version loaded from `{name}@{version}` as `:current`" do
+ subject.expects(:require).with('puppet/string/huzzah').raises(LoadError)
+ subject.expects(:require).with do |file|
+ @strings[:huzzah]['0.0.1'] = true
+ file == 'huzzah@0.0.1/puppet/string/huzzah'
+ end
+ subject.string?("huzzah", '0.0.1')
+ @strings[:huzzah].should_not have_key(:current)
+ end
end
describe "::register" do
diff --git a/spec/unit/string_spec.rb b/spec/unit/string_spec.rb
index 73d1f2177..64d4f12f8 100755
--- a/spec/unit/string_spec.rb
+++ b/spec/unit/string_spec.rb
@@ -75,7 +75,8 @@ describe Puppet::String do
end
it "should try to require strings that are not known" do
- Puppet::String::StringCollection.expects(:require).with "puppet/string/v0.0.1/foo"
+ Puppet::String::StringCollection.expects(:require).with "puppet/string/foo"
+ Puppet::String::StringCollection.expects(:require).with "foo@0.0.1/puppet/string/foo"
Puppet::String[:foo, '0.0.1']
end