From 104192db739b559ba8a7ecb5c6936b4ce9d0f8e4 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Fri, 3 Feb 2012 10:13:16 -0800 Subject: [PATCH] (#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. --- .../resource_refs_with_nested_arrays.rb | 22 ++++++++-------- .../ticket_4655_default_stage_for_classes.rb | 25 +++++++++++-------- .../ticket_4233_resource_with_a_newline.rb | 3 ++- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/acceptance/tests/language/resource_refs_with_nested_arrays.rb b/acceptance/tests/language/resource_refs_with_nested_arrays.rb index 7bc797885..ead35a3f5 100644 --- a/acceptance/tests/language/resource_refs_with_nested_arrays.rb +++ b/acceptance/tests/language/resource_refs_with_nested_arrays.rb @@ -1,27 +1,27 @@ test_name "#7681: Allow using array variables in resource references" -test_manifest = < "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 diff --git a/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb b/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb index 1b0b537bf..be5a16746 100644 --- a/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb +++ b/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb @@ -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 = < 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 diff --git a/acceptance/tests/ticket_4233_resource_with_a_newline.rb b/acceptance/tests/ticket_4233_resource_with_a_newline.rb index 11924b550..1ed1ce83b 100644 --- a/acceptance/tests/ticket_4233_resource_with_a_newline.rb +++ b/acceptance/tests/ticket_4233_resource_with_a_newline.rb @@ -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