Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make :content mandatory #1

Merged
merged 3 commits into from
Feb 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ This will create a file `/etc/facter/facts.d/env.txt` containing:

environment=production

If the `$target` is not specified, it defaults to the name of the resource.
* `content is mandatory. It can not be empty string or whitespace.
* `$target` is optional. It defaults to the name of the resource.
* `ensure` is optional. It defaults to `present`.
3 changes: 2 additions & 1 deletion lib/puppet/type/fact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

newproperty(:content) do
desc "The content of the fact"
defaultto ''
validate do |value|
raise ArgumentError, "Content cannot be whitespace" if value.match(/^\s+$/)
fail("Content cannot be empty or whitespace") if value.match(/^\s*$/)
end
end

Expand Down
12 changes: 10 additions & 2 deletions spec/unit/type/fact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
end

context "when validating content" do
it "should be mandatory" do
expect { described_class.new(:name => "environment") }.to raise_error
end

it "should reject empty string" do
expect { described_class.new(:name => "environment", :content => "") }.to raise_error
end

it "should reject only whitespace" do
expect { described_class.new(:name => "environment", :content => " ") }.to raise_error
end
Expand All @@ -30,7 +38,7 @@
end

context "when validating target" do
resource = described_class.new(:name => "environment")
resource = described_class.new(:name => "environment", :content => "production")

it "can be optional" do
expect { resource }.to_not raise_error
Expand All @@ -41,7 +49,7 @@
end

it "should accept specified values" do
described_class.new(:name => "environment", :target => "env").should(:target).should == "env"
described_class.new(:name => "environment", :content => "production", :target => "env").should(:target).should == "env"
end
end

Expand Down