diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-20 15:51:39 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-21 12:37:26 -0700 |
| commit | f17f6bba87519db888854acf7017ddff61f635be (patch) | |
| tree | dc092056e59e018bb6e56f1c4918685220d21ad9 /spec/unit/interface | |
| parent | 7414ee7ebda1052f4c52f3e5565726f20de5a20b (diff) | |
(#7183) Implement "invisible glob" version matching for faces
"Invisible glob", or "prefix", version matching means that when you specify a
version string to use you can specify as little as one version number out of
the semantic versioning spec.
Matching is done on the prefix; an omitted number is treated as "anything" in
that slot, and we return the highest matching versioned face by that spec.
For example, given the set of versions: 1.0.0, 1.0.1, 1.1.0, 1.1.1, 2.0.0
The following would be matched:
input matched
1 1.1.1
1.0 1.0.1
1.0.1 1.0.1
1.0.2 fail - no match
1.1 1.1.1
1.1.1 1.1.1
1.2 fail - no match
Diffstat (limited to 'spec/unit/interface')
| -rwxr-xr-x | spec/unit/interface/face_collection_spec.rb | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/spec/unit/interface/face_collection_spec.rb b/spec/unit/interface/face_collection_spec.rb index c3e43435c..890e06a9e 100755 --- a/spec/unit/interface/face_collection_spec.rb +++ b/spec/unit/interface/face_collection_spec.rb @@ -24,6 +24,22 @@ describe Puppet::Interface::FaceCollection do $".clear ; @original_required.each do |item| $" << item end end + describe "::prefix_match?" do + # want have + { ['1.0.0', '1.0.0'] => true, + ['1.0', '1.0.0'] => true, + ['1', '1.0.0'] => true, + ['1.0.0', '1.1.0'] => false, + ['1.0', '1.1.0'] => false, + ['1', '1.1.0'] => true, + ['1.0.1', '1.0.0'] => false, + }.each do |data, result| + it "should return #{result.inspect} for prefix_match?(#{data.join(', ')})" do + subject.prefix_match?(*data).should == result + end + end + end + describe "::validate_version" do { '10.10.10' => true, '1.2.3.4' => false, @@ -56,12 +72,10 @@ describe Puppet::Interface::FaceCollection do subject.expects(:require).with('puppet/face/fozzie') subject['fozzie', :current] end - end - describe "::face?" do it "should return true if the face specified is registered" do subject.instance_variable_get("@faces")[:foo]['0.0.1'] = 10 - subject.face?("foo", '0.0.1').should == true + subject["foo", '0.0.1'].should == 10 end it "should attempt to require the face if it is not registered" do @@ -69,24 +83,18 @@ describe Puppet::Interface::FaceCollection do subject.instance_variable_get("@faces")[:bar]['0.0.1'] = true file == 'puppet/face/bar' end - subject.face?("bar", '0.0.1').should == true - end - - it "should return true if requiring the face registered it" do - subject.stubs(:require).with do - subject.instance_variable_get("@faces")[:bar]['0.0.1'] = 20 - end + subject["bar", '0.0.1'].should be_true end it "should return false if the face is not registered" do subject.stubs(:require).returns(true) - subject.face?("bar", '0.0.1').should be_false + subject["bar", '0.0.1'].should be_false end it "should return false if the face file itself is missing" do subject.stubs(:require). raises(LoadError, 'no such file to load -- puppet/face/bar') - subject.face?("bar", '0.0.1').should be_false + subject["bar", '0.0.1'].should be_false end it "should register the version loaded by `:current` as `:current`" do @@ -94,26 +102,26 @@ describe Puppet::Interface::FaceCollection do subject.instance_variable_get("@faces")[:huzzah]['2.0.1'] = :huzzah_face file == 'puppet/face/huzzah' end - subject.face?("huzzah", :current) + subject["huzzah", :current] subject.instance_variable_get("@faces")[:huzzah][:current].should == :huzzah_face end context "with something on disk" do it "should register the version loaded from `puppet/face/{name}` as `:current`" do - subject.should be_face "huzzah", '2.0.1' - subject.should be_face "huzzah", :current + subject["huzzah", '2.0.1'].should be + subject["huzzah", :current].should be Puppet::Face[:huzzah, '2.0.1'].should == Puppet::Face[:huzzah, :current] end it "should index :current when the code was pre-required" do subject.instance_variable_get("@faces")[:huzzah].should_not be_key :current require 'puppet/face/huzzah' - subject.face?(:huzzah, :current).should be_true + subject[:huzzah, :current].should be_true end end it "should not cause an invalid face to be enumerated later" do - subject.face?(:there_is_no_face, :current).should be_false + subject[:there_is_no_face, :current].should be_false subject.faces.should_not include :there_is_no_face end end |
