[Pkg-puppet-devel] [facter] 160/352: (maint) set resolution properties from an options hash
Stig Sandbeck Mathisen
ssm at debian.org
Sun Apr 6 22:21:41 UTC 2014
This is an automated email from the git hooks/post-receive script.
ssm pushed a commit to branch master
in repository facter.
commit dc65014afc5849d2d987cf636c8ee1836491f4d5
Author: Adrien Thebo <git at somethingsinistral.net>
Date: Mon Dec 30 12:01:45 2013 -0800
(maint) set resolution properties from an options hash
---
lib/facter/util/resolution.rb | 22 ++++++++++++++++++++++
spec/unit/util/resolution_spec.rb | 25 +++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb
index 732bf68..c36ecc9 100644
--- a/lib/facter/util/resolution.rb
+++ b/lib/facter/util/resolution.rb
@@ -105,6 +105,28 @@ class Facter::Util::Resolution
@weight = nil
end
+ def set_options(options)
+ ret = {}
+
+ if options[:value]
+ @value = options.delete(:value)
+ end
+
+ if options[:timeout]
+ @timeout = options.delete(:timeout)
+ end
+
+ if options[:weight]
+ @weight = options.delete(:weight)
+ end
+
+ if not options.keys.empty?
+ raise ArgumentError, "Invalid resolution options #{options.keys.inspect}"
+ end
+
+ ret
+ end
+
# Returns the importance of this resolution. If the weight was not
# given, the number of confines is used instead (so that a more
# specific resolution wins over a less specific one).
diff --git a/spec/unit/util/resolution_spec.rb b/spec/unit/util/resolution_spec.rb
index ed2c762..a6b954e 100755
--- a/spec/unit/util/resolution_spec.rb
+++ b/spec/unit/util/resolution_spec.rb
@@ -331,4 +331,29 @@ describe Facter::Util::Resolution do
@resolve.should be_suitable
end
end
+
+ describe "setting options" do
+ subject(:resolution) { described_class.new(:foo) }
+
+ it "can set the value" do
+ resolution.set_options(:value => 'something')
+ expect(resolution.value).to eq 'something'
+ end
+
+ it "can set the timeout" do
+ resolution.set_options(:timeout => 314)
+ expect(resolution.limit).to eq 314
+ end
+
+ it "can set the weight" do
+ resolution.set_options(:weight => 27)
+ expect(resolution.weight).to eq 27
+ end
+
+ it "fails on unhandled options" do
+ expect do
+ resolution.set_options(:foo => 'bar')
+ end.to raise_error(ArgumentError, /Invalid resolution options.*foo/)
+ end
+ end
end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git
More information about the Pkg-puppet-devel
mailing list