Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds syntax checking before an rsync
- Loading branch information
Showing
9 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module SupplyDrop | ||
class SyntaxChecker | ||
def initialize(path) | ||
@path = path | ||
end | ||
|
||
def validate_puppet_files | ||
Dir.glob("#{@path}/**/*.pp").map do |puppet_file| | ||
output = `puppet parser validate #{puppet_file}` | ||
$?.to_i == 0 ? nil : [puppet_file, output] | ||
end.compact | ||
end | ||
|
||
def validate_templates | ||
Dir.glob("#{@path}/**/*.erb").map do |template_file| | ||
output = `erb -x -T '-' #{template_file} | ruby -c 2>&1` | ||
$?.to_i == 0 ? nil : [template_file, output] | ||
end.compact | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class example { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class valid { | ||
file { "/etc/hosts": | ||
ensure => present, | ||
content => "127.0.0.1 localhost", | ||
owner => root, | ||
group => root, | ||
mode => "0644" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is a <%= if true %> template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is a <%= "good" %> template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'test/unit' | ||
require File.expand_path('../../lib/supply_drop/syntax_checker', __FILE__) | ||
|
||
class SyntaxCheckerTest < Test::Unit::TestCase | ||
|
||
def test_syntax_checks_puppet_files | ||
checker = SupplyDrop::SyntaxChecker.new(File.expand_path('../files', __FILE__)) | ||
errors = checker.validate_puppet_files | ||
assert_equal 1, errors.count | ||
file, error = errors.first | ||
assert_match %r[manifests/invalid.pp$], file | ||
assert_match %r[expected '\}'], error | ||
end | ||
|
||
def test_synatx_checks_erb_files | ||
checker = SupplyDrop::SyntaxChecker.new(File.expand_path('../files', __FILE__)) | ||
errors = checker.validate_templates | ||
assert_equal 1, errors.count | ||
file, error = errors.first | ||
assert_match %r[templates/invalid.erb$], file | ||
assert_match %r[syntax error], error | ||
end | ||
end |