1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
test_name 'parser validate' do
tag 'audit:high',
'audit:unit' # Parser validation should be core to ruby
# and platform agnostic.
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
app_type = File.basename(__FILE__, '.*')
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
agents.each do |agent|
skip_test('this test fails on windows French due to Cygwin/UTF Issues - PUP-8319,IMAGES-492') if agent['platform'] =~ /windows/ && agent['locale'] == 'fr'
step 'manifest with parser function call' do
if agent.platform !~ /windows/
tmp_environment = mk_tmp_environment_with_teardown(agent, app_type)
create_sitepp(agent, tmp_environment, <<-SITE)
function validate_this() {
notice('hello, puppet')
}
validate_this()
SITE
on(agent, puppet("parser validate --environment #{tmp_environment}"), :pty => true) # default manifest
end
# manifest with Type aliases
create_test_file(agent, "#{app_type}.pp", <<-PP)
function validate_this() {
notice('hello, puppet')
}
validate_this()
type MyInteger = Integer
notice 42 =~ MyInteger
PP
tmp_manifest = get_test_file_path(agent, "#{app_type}.pp")
on(agent, puppet("parser validate #{tmp_manifest}"))
end
step 'manifest with bad syntax' do
create_test_file(agent, "#{app_type}_broken.pp", "notify 'hello there'")
tmp_manifest = get_test_file_path(agent, "#{app_type}_broken.pp")
on(agent, puppet("parser validate #{tmp_manifest}"), :accept_all_exit_codes => true) do |result|
assert_equal(result.exit_code, 1, 'parser validate did not exit with 1 upon parse failure')
expected = /Error: Could not parse for environment production: This Name has no effect\. A value was produced and then forgotten \(one or more preceding expressions may have the wrong form\) \(file: .*_broken\.pp, line: 1, column: 1\)/
assert_match(expected, result.output, "parser validate did not output correctly: '#{result.output}'. expected: '#{expected.to_s}'") unless agent['locale'] == 'ja'
end
end
step '(large) manifest with exported resources' do
fixture_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures/manifest_large_exported_classes_node.pp')
create_test_file(agent, "#{app_type}_exported.pp", File.read(fixture_path))
tmp_manifest = get_test_file_path(agent, "#{app_type}_exported.pp")
on(agent, puppet("parser validate #{tmp_manifest}"))
end
end
end
|