(#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:
Родитель
dce3d58e4d
Коммит
104192db73
|
@ -1,27 +1,27 @@
|
|||
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 { "first":
|
||||
command => "echo the first command",
|
||||
path => "/usr/bin:/bin",
|
||||
command => "#{agent.echo('the first command')}",
|
||||
path => "#{agent.path}",
|
||||
logoutput => true,
|
||||
}
|
||||
exec { "second":
|
||||
command => "echo the second command",
|
||||
path => "/usr/bin:/bin",
|
||||
command => "#{agent.echo('the second command')}",
|
||||
path => "#{agent.path}",
|
||||
logoutput => true,
|
||||
}
|
||||
exec { "third":
|
||||
command => "echo the final command",
|
||||
path => "/usr/bin:/bin",
|
||||
command => "#{agent.echo('the final command')}",
|
||||
path => "#{agent.path}",
|
||||
logoutput => true,
|
||||
require => Exec[$exec_names],
|
||||
}
|
||||
MANIFEST
|
||||
|
||||
results = apply_manifest_on agents, test_manifest
|
||||
|
||||
results.each do |result|
|
||||
assert_match(/Exec\[third\].*the final command/, "#{result.stdout}")
|
||||
apply_manifest_on agent, test_manifest do
|
||||
assert_match(/Exec\[third\].*the final command/, "#{stdout}")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,39 +1,42 @@
|
|||
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
|
||||
stage { one: before => Stage[two] }
|
||||
stage { two: before => Stage[three] }
|
||||
stage { three: before => Stage[main] }
|
||||
|
||||
class in_one {
|
||||
exec { "echo 'in_one' > #{temp_file_name}":
|
||||
path => '/usr/bin:/bin',
|
||||
exec { "#{agent.echo('in_one', false)} > #{temp_file_name}":
|
||||
path => '#{agent.path}',
|
||||
}
|
||||
}
|
||||
class { in_one: stage => "one" }
|
||||
|
||||
class in_two( $stage=two ){
|
||||
exec { "echo 'in_two' >> #{temp_file_name}":
|
||||
path => '/usr/bin:/bin',
|
||||
exec { "#{agent.echo('in_two', false)} >> #{temp_file_name}":
|
||||
path => '#{agent.path}',
|
||||
}
|
||||
}
|
||||
class { in_two: }
|
||||
|
||||
class in_three {
|
||||
exec { "echo 'in_three' >> #{temp_file_name}":
|
||||
path => '/usr/bin:/bin',
|
||||
exec { "#{agent.echo('in_three', false)} >> #{temp_file_name}":
|
||||
path => '#{agent.path}',
|
||||
}
|
||||
}
|
||||
class { "in_three": stage => "three" }
|
||||
HERE
|
||||
|
||||
expected_results = "in_one
|
||||
expected_results = "in_one
|
||||
in_two
|
||||
in_three
|
||||
"
|
||||
apply_manifest_on agents, test_manifest
|
||||
apply_manifest_on agent, test_manifest
|
||||
|
||||
on(agents, "cat #{temp_file_name}").each do |result|
|
||||
assert_equal(expected_results, "#{result.stdout}", "Unexpected result for host '#{result.host}'")
|
||||
on(agent, "cat #{temp_file_name}") do
|
||||
# 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
|
||||
|
|
|
@ -10,7 +10,8 @@ test_name "#4233: resource with a newline"
|
|||
# if we find it.
|
||||
|
||||
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}")
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче