(#12412) Refactor execution of echo in acceptance tests

Previously, some of the acceptance tests were using `/bin/echo ...` as
the command for an exec resource, which doesn't work on Windows
agents.

This commit refactors the tests to use the `Host#echo` method, which
generates a platform-specific command for executing echo. By default,
the method generates a fully-qualified path for executing echo, but if
you pass false, then it generates an unqualified path (for cases where
the manifest specifies the path to use).

The commit also refactors the tests to use `agents.each do |agent|`
style test, which is necessary to generate platform-specific commands.
This commit is contained in:
Josh Cooper 2012-02-03 10:13:16 -08:00
Родитель dce3d58e4d
Коммит 104192db73
3 изменённых файлов: 27 добавлений и 23 удалений

Просмотреть файл

@ -1,27 +1,27 @@
test_name "#7681: Allow using array variables in resource references" test_name "#7681: Allow using array variables in resource references"
test_manifest = <<MANIFEST agents.each do |agent|
test_manifest = <<MANIFEST
$exec_names = ["first", "second"] $exec_names = ["first", "second"]
exec { "first": exec { "first":
command => "echo the first command", command => "#{agent.echo('the first command')}",
path => "/usr/bin:/bin", path => "#{agent.path}",
logoutput => true, logoutput => true,
} }
exec { "second": exec { "second":
command => "echo the second command", command => "#{agent.echo('the second command')}",
path => "/usr/bin:/bin", path => "#{agent.path}",
logoutput => true, logoutput => true,
} }
exec { "third": exec { "third":
command => "echo the final command", command => "#{agent.echo('the final command')}",
path => "/usr/bin:/bin", path => "#{agent.path}",
logoutput => true, logoutput => true,
require => Exec[$exec_names], require => Exec[$exec_names],
} }
MANIFEST MANIFEST
results = apply_manifest_on agents, test_manifest apply_manifest_on agent, test_manifest do
assert_match(/Exec\[third\].*the final command/, "#{stdout}")
results.each do |result| end
assert_match(/Exec\[third\].*the final command/, "#{result.stdout}")
end end

Просмотреть файл

@ -1,39 +1,42 @@
test_name "#4655: Allow setting the default stage for parameterized classes" test_name "#4655: Allow setting the default stage for parameterized classes"
temp_file_name = "/tmp/4655-stage-in-parameterized-class.#{$$}" agents.each do |agent|
temp_file_name = agent.tmpfile('4655-stage-in-parameterized-class')
test_manifest = <<HERE test_manifest = <<HERE
stage { one: before => Stage[two] } stage { one: before => Stage[two] }
stage { two: before => Stage[three] } stage { two: before => Stage[three] }
stage { three: before => Stage[main] } stage { three: before => Stage[main] }
class in_one { class in_one {
exec { "echo 'in_one' > #{temp_file_name}": exec { "#{agent.echo('in_one', false)} > #{temp_file_name}":
path => '/usr/bin:/bin', path => '#{agent.path}',
} }
} }
class { in_one: stage => "one" } class { in_one: stage => "one" }
class in_two( $stage=two ){ class in_two( $stage=two ){
exec { "echo 'in_two' >> #{temp_file_name}": exec { "#{agent.echo('in_two', false)} >> #{temp_file_name}":
path => '/usr/bin:/bin', path => '#{agent.path}',
} }
} }
class { in_two: } class { in_two: }
class in_three { class in_three {
exec { "echo 'in_three' >> #{temp_file_name}": exec { "#{agent.echo('in_three', false)} >> #{temp_file_name}":
path => '/usr/bin:/bin', path => '#{agent.path}',
} }
} }
class { "in_three": stage => "three" } class { "in_three": stage => "three" }
HERE HERE
expected_results = "in_one expected_results = "in_one
in_two in_two
in_three in_three
" "
apply_manifest_on agents, test_manifest apply_manifest_on agent, test_manifest
on(agents, "cat #{temp_file_name}").each do |result| on(agent, "cat #{temp_file_name}") do
assert_equal(expected_results, "#{result.stdout}", "Unexpected result for host '#{result.host}'") # echo on windows adds \r\n, so do dotall regexp match
assert_match(/in_one\s*in_two\s*\in_three/m, stdout, "Unexpected result for host '#{agent}'")
end
end end

Просмотреть файл

@ -10,7 +10,8 @@ test_name "#4233: resource with a newline"
# if we find it. # if we find it.
agents.each do |host| agents.each do |host|
apply_manifest_on(host, 'exec { \'/bin/echo -e "\nHello World\n"\': }') do resource = host.echo('-e "\nHello World\n"')
apply_manifest_on(host, "exec { '#{resource}': }") do
assert_no_match(/err:/, stdout, "error report in output on #{host}") assert_no_match(/err:/, stdout, "error report in output on #{host}")
end end
end end