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

issues-122 Sync files that do not conform to *.erb #136

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions features/update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,40 @@ Feature: update
Given I run `cat modules/puppet-test/test`
Then the output should contain "aruba"

Scenario: Adding 2 files, with the same basename
Given a file named "managed_modules.yml" with:
"""
---
- puppet-test
"""
And a file named "modulesync.yml" with:
"""
---
namespace: maestrodev
git_base: https://github.com/
"""
And a file named "config_defaults.yml" with:
"""
---
test.erb:
name: aruba
"""
And a directory named "moduleroot"
And a file named "moduleroot/test" with:
"""
<%= @configs['name'] %>
"""
And a file named "moduleroot/test.erb" with:
"""
<%= @configs['name'] %>
"""
When I run `msync update --noop`
Then the exit status should be 0
And the output should match:
"""
Collision: You cannot have 2 files in ./moduleroot/ with the same basename
"""

Scenario: Adding a new file using global values
Given a file named "managed_modules.yml" with:
"""
Expand Down
10 changes: 8 additions & 2 deletions lib/modulesync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ def self.module_file(project_root, puppet_module, file)

def self.local_files(path)
if File.exist?(path)
# only select *.erb files, and strip the extension. This way all the code will only have to handle bare paths, except when reading the actual ERB text
local_files = Find.find(path).find_all { |p| p =~ /.erb$/ && !File.directory?(p) }.collect { |p| p.chomp('.erb') }.to_a
# select all files. *.erb files strip the extension. This way all the code will only have to handle bare paths, except when reading the actual ERB text
local_files = Find.find(path).find_all { |p| !File.directory?(p) }.collect { |p| p.chomp('.erb') }.to_a
duplicates = local_files.find_all { |e| local_files.rindex(e) != local_files.index(e) }.uniq
unless duplicates.empty?
puts "Collision: You cannot have 2 files in #{path} with the same basename eg '#{path}example.erb' and '#{path}example'. The offending basenames: #{duplicates}."
exit
end
local_files
else
puts "#{path} does not exist. Check that you are working in your module configs directory or that you have passed in the correct directory with -c."
exit
Expand Down