summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2011-07-12 16:17:43 -0700
committerMatt Robinson <matt@puppetlabs.com>2011-07-12 16:17:43 -0700
commit8730b290c4f45f3f76d57d2648bfb642528d0762 (patch)
treed082e9654a46f77e820fb17723a60ce252e201c2
parent1feccc3f2db29d112308a55032e7f93ca44b45aa (diff)
parent45b3908e03734388b6c699ffbc4223f43b44a1d5 (diff)
downloadpuppet-8730b290c4f45f3f76d57d2648bfb642528d0762.tar.gz
puppet-8730b290c4f45f3f76d57d2648bfb642528d0762.tar.xz
puppet-8730b290c4f45f3f76d57d2648bfb642528d0762.zip
Merge branch 'ticket/2.7.x/4142-metadata_json' into 2.7.x
* ticket/2.7.x/4142-metadata_json: (#4142) Fix module check not to fail when empty metadata.json
-rw-r--r--lib/puppet/module.rb5
-rwxr-xr-xspec/unit/module_spec.rb47
2 files changed, 42 insertions, 10 deletions
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 059591ed8..00468df96 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -42,7 +42,10 @@ class Puppet::Module
def has_metadata?
return false unless metadata_file
- FileTest.exist?(metadata_file)
+ return false unless FileTest.exist?(metadata_file)
+
+ metadata = PSON.parse File.read(metadata_file)
+ return metadata.is_a?(Hash) && !metadata.keys.empty?
end
def initialize(name, environment = nil)
diff --git a/spec/unit/module_spec.rb b/spec/unit/module_spec.rb
index 8d38657f9..822c76296 100755
--- a/spec/unit/module_spec.rb
+++ b/spec/unit/module_spec.rb
@@ -505,12 +505,38 @@ describe Puppet::Module do
mod.metadata_file.should == mod.metadata_file
end
- it "should know if it has a metadata file" do
+ it "should have metadata if it has a metadata file and its data is not empty" do
FileTest.expects(:exist?).with(@module.metadata_file).returns true
+ File.stubs(:read).with(@module.metadata_file).returns "{\"foo\" : \"bar\"}"
@module.should be_has_metadata
end
+ it "should have metadata if it has a metadata file and its data is not empty" do
+ FileTest.expects(:exist?).with(@module.metadata_file).returns true
+ File.stubs(:read).with(@module.metadata_file).returns "{\"foo\" : \"bar\"}"
+
+ @module.should be_has_metadata
+ end
+
+ it "should not have metadata if has a metadata file and its data is empty" do
+ FileTest.expects(:exist?).with(@module.metadata_file).returns true
+ File.stubs(:read).with(@module.metadata_file).returns "/*
++-----------------------------------------------------------------------+
+| |
+| ==> DO NOT EDIT THIS FILE! <== |
+| |
+| You should edit the `Modulefile` and run `puppet-module build` |
+| to generate the `metadata.json` file for your releases. |
+| |
++-----------------------------------------------------------------------+
+*/
+
+{}"
+
+ @module.should_not be_has_metadata
+ end
+
it "should know if it is missing a metadata file" do
FileTest.expects(:exist?).with(@module.metadata_file).returns false
@@ -528,16 +554,16 @@ describe Puppet::Module do
Puppet::Module.new("yay")
end
- describe "when loading the medatada file", :if => Puppet.features.json? do
+ describe "when loading the medatada file", :if => Puppet.features.pson? do
before do
@data = {
- :license => "GPL2",
- :author => "luke",
- :version => "1.0",
- :source => "http://foo/",
+ :license => "GPL2",
+ :author => "luke",
+ :version => "1.0",
+ :source => "http://foo/",
:puppetversion => "0.25"
}
- @text = @data.to_json
+ @text = @data.to_pson
@module = Puppet::Module.new("foo")
@module.stubs(:metadata_file).returns "/my/file"
@@ -552,9 +578,12 @@ describe Puppet::Module do
it "should fail if #{attr} is not present in the metadata file" do
@data.delete(attr.to_sym)
- @text = @data.to_json
+ @text = @data.to_pson
File.stubs(:read).with("/my/file").returns @text
- lambda { @module.load_metadata }.should raise_error(Puppet::Module::MissingMetadata)
+ lambda { @module.load_metadata }.should raise_error(
+ Puppet::Module::MissingMetadata,
+ "No #{attr} module metadata provided for foo"
+ )
end
end