Skip to content

Commit

Permalink
Issue #250 Fix error when module has no dependencies in metadata.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Sanchez committed Aug 22, 2014
1 parent c8f3e7d commit a028cc5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## From 1.1.x Librarian-Puppet requires Ruby >= 1.9, uses Puppet Forge API v3. For Ruby 1.8 use 1.0.x

### 1.3.3

* [Issue #250](https://github.com/rodjek/librarian-puppet/issues/250) Fix error when module has no dependencies in `metadata.json`

### 1.3.2

* [Issue #246](https://github.com/rodjek/librarian-puppet/issues/246) Do not fail if modules have no `Modulefile` nor `metadata.json`
Expand Down Expand Up @@ -46,6 +50,10 @@

## 1.0.x: Works on Ruby 1.8, using Puppet Forge API v1

### 1.0.10

* [Issue #250](https://github.com/rodjek/librarian-puppet/issues/250) Fix error when module has no dependencies in `metadata.json`

### 1.0.9

* [Issue #246](https://github.com/rodjek/librarian-puppet/issues/246) Do not fail if modules have no `Modulefile` nor `metadata.json`
Expand Down
10 changes: 0 additions & 10 deletions features/install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,3 @@ Feature: cli/install
"""
Unable to parse .*/bad_modulefile/Modulefile, ignoring: Missing version
"""

Scenario: Running install with no Modulefile nor metadata.json
Given a file named "Puppetfile" with:
"""
forge "http://forge.puppetlabs.com"
mod 'puppetlabs/stdlib', :git => 'https://github.com/puppetlabs/puppetlabs-stdlib.git', :ref => '3.0.0'
"""
When I run `librarian-puppet install`
Then the exit status should be 0
20 changes: 20 additions & 0 deletions features/install/git.feature
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ Feature: cli/install/git
And the file "modules/with_puppetfile/Modulefile" should match /name *'librarian-with_puppetfile_and_modulefile'/
And the file "modules/test/Modulefile" should match /name *'maestrodev-test'/

Scenario: Running install with no Modulefile nor metadata.json
Given a file named "Puppetfile" with:
"""
forge "http://forge.puppetlabs.com"
mod 'puppetlabs/stdlib', :git => 'https://github.com/puppetlabs/puppetlabs-stdlib.git', :ref => '3.0.0'
"""
When I run `librarian-puppet install`
Then the exit status should be 0

Scenario: Running install with metadata.json without dependencies
Given a file named "Puppetfile" with:
"""
forge "http://forge.puppetlabs.com"
mod 'puppetlabs/sqlite', :git => 'https://github.com/puppetlabs/puppetlabs-sqlite.git', :ref => '84a0a6'
"""
When I run `librarian-puppet install`
Then the exit status should be 0

Scenario: Install a module using modulefile syntax
Given a file named "Puppetfile" with:
"""
Expand Down
37 changes: 19 additions & 18 deletions lib/librarian/puppet/source/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,25 @@ def evaluate_modulefile(modulefile)
end

def parsed_metadata
@metadata ||= if metadata?
JSON.parse(File.read(metadata))
elsif modulefile?
# translate Modulefile to metadata.json
evaluated = evaluate_modulefile(modulefile)
{
'version' => evaluated.version,
'dependencies' => evaluated.dependencies.map do |dependency|
{
'name' => dependency.instance_variable_get(:@full_module_name),
'version_requirement' => dependency.instance_variable_get(:@version_requirement)
}
end
}
else
{
'dependencies' => []
}
if @metadata.nil?
@metadata = if metadata?
JSON.parse(File.read(metadata))
elsif modulefile?
# translate Modulefile to metadata.json
evaluated = evaluate_modulefile(modulefile)
{
'version' => evaluated.version,
'dependencies' => evaluated.dependencies.map do |dependency|
{
'name' => dependency.instance_variable_get(:@full_module_name),
'version_requirement' => dependency.instance_variable_get(:@version_requirement)
}
end
}
else
{}
end
@metadata['dependencies'] ||= []
end
@metadata
end
Expand Down

0 comments on commit a028cc5

Please sign in to comment.