Browse files

(#12412) Refactor puppet_resource('file')

Previously, the file acceptance tests were failing on Windows agents
due to using POSIX style paths.

This commit changes them to use the `agent.tmpfile` command to
generate a valid temp file for that agent.
  • Loading branch information...
1 parent fb28ce0 commit 41e91d800a58fb19f18dd37941b5fd7b7c294b70 @joshcooper joshcooper committed Feb 1, 2012
View
47 acceptance/tests/resource/file/content_attribute.rb
@@ -1,30 +1,31 @@
test_name "Content Attribute"
-step "Ensure the test environment is clean"
-on agents, 'rm -f /tmp/content_file_test.txt'
+agents.each do |agent|
+ target = agent.tmpfile('content_file_test')
+
+ step "Ensure the test environment is clean"
+ on agent, "rm -f #{target}"
-step "Content Attribute: using raw content"
+ step "Content Attribute: using raw content"
-manifest = "file { '/tmp/content_file_test.txt': content => 'This is the test file content', ensure => present }"
-apply_manifest_on agents, manifest
+ manifest = "file { '#{target}': content => 'This is the test file content', ensure => present }"
+ apply_manifest_on agent, manifest
-agents.each do |host|
- on host, "cat /tmp/content_file_test.txt" do
- assert_match(/This is the test file content/, stdout, "File content not matched on #{host}")
+ on agent, "cat #{target}" do
+ assert_match(/This is the test file content/, stdout, "File content not matched on #{agent}")
end
-end
-step "Ensure the test environment is clean"
-on agents, 'rm -f /tmp/content_file_test.txt'
+ step "Ensure the test environment is clean"
+ on agent, "rm -f #{target}"
-step "Content Attribute: using a checksum from filebucket"
-on agents, "echo 'This is the checksum file contents' > /tmp/checksum_test_file.txt"
-step "Backup file into the filebucket"
-on agents, puppet_filebucket("backup --local /tmp/checksum_test_file.txt")
+ step "Content Attribute: using a checksum from filebucket"
+ on agent, "echo 'This is the checksum file contents' > #{target}"
+
+ step "Backup file into the filebucket"
+ on agent, puppet_filebucket("backup --local #{target}")
-agents.each do |agent|
bucketdir="not set"
- on agent, puppet_filebucket("--configprint bucketdir") do
+ on agent, puppet_filebucket("--configprint bucketdir") do
bucketdir = stdout.chomp
end
@@ -33,20 +34,18 @@
path => '#{bucketdir}',
}
- file { '/tmp/content_file_test.txt':
+ file { '#{target}':
content => '{md5}18571d3a04b2bb7ccfdbb2c44c72caa9',
ensure => present,
backup => local,
}
|
- step "Applying Manifest on Agents"
+ step "Applying Manifest on Agent"
apply_manifest_on agent, manifest
-end
-step "Validate filebucket checksum file contents"
-agents.each do |host|
- on host, "cat /tmp/content_file_test.txt" do
- assert_match(/This is the checksum file content/, stdout, "File content not matched on #{host}")
+ step "Validate filebucket checksum file contents"
+ on agent, "cat #{target}" do
+ assert_match(/This is the checksum file content/, stdout, "File content not matched on #{agent}")
end
end
View
20 acceptance/tests/resource/file/should_create_directory.rb
@@ -1,15 +1,17 @@
test_name "should create directory"
-target = "/tmp/test-#{Time.new.to_i}"
+agents.each do |agent|
+ target = agent.tmpfile("create-dir")
-step "clean up the system before we begin"
-on agents, "rm -rf #{target}"
+ step "clean up the system before we begin"
+ on(agent, "rm -rf #{target}")
-step "verify we can create a directory"
-on(agents, puppet_resource("file", target, 'ensure=directory'))
+ step "verify we can create a directory"
+ on(agent, puppet_resource("file", target, 'ensure=directory'))
-step "verify the directory was created"
-on agents, "test -d #{target}"
+ step "verify the directory was created"
+ on(agent, "test -d #{target}")
-step "clean up after the test run"
-on agents, "rm -rf #{target}"
+ step "clean up after the test run"
+ on(agent, "rm -rf #{target}")
+end
View
20 acceptance/tests/resource/file/should_create_empty.rb
@@ -1,15 +1,17 @@
test_name "should create empty file for 'present'"
-target = "/tmp/test-#{Time.new.to_i}"
+agents.each do |agent|
+ target = agent.tmpfile("empty")
-step "clean up the system before we begin"
-on agents, "rm -rf #{target}"
+ step "clean up the system before we begin"
+ on(agent, "rm -rf #{target}")
-step "verify we can create an empty file"
-on(agents, puppet_resource("file", target, 'ensure=present'))
+ step "verify we can create an empty file"
+ on(agent, puppet_resource("file", target, 'ensure=present'))
-step "verify the target was created"
-on agents, "test -f #{target} && test ! -s #{target}"
+ step "verify the target was created"
+ on(agent, "test -f #{target} && test ! -s #{target}")
-step "clean up after the test run"
-on agents, "rm -rf #{target}"
+ step "clean up after the test run"
+ on(agent, "rm -rf #{target}")
+end
View
39 acceptance/tests/resource/file/should_create_symlink.rb
@@ -4,25 +4,32 @@
target = "/tmp/test-#{Time.new.to_i}"
source = "/tmp/test-#{Time.new.to_i}-source"
-step "clean up the system before we begin"
-on agents, "rm -rf #{target}"
-on agents, "echo '#{message}' > #{source}"
+agents.each do |agent|
+ if agent['platform'].include?('windows')
+ skip_test "Test not supported on this platform"
+ next
+ end
-step "verify we can create a symlink"
-on(agents, puppet_resource("file", target, "ensure=#{source}"))
+ step "clean up the system before we begin"
+ on agent, "rm -rf #{target}"
+ on agent, "echo '#{message}' > #{source}"
-step "verify the symlink was created"
-on agents, "test -L #{target} && test -f #{target}"
-step "verify source file"
-on agents, "test -f #{source}"
+ step "verify we can create a symlink"
+ on(agent, puppet_resource("file", target, "ensure=#{source}"))
-step "verify the content is identical on both sides"
-on(agents, "cat #{source}") do
+ step "verify the symlink was created"
+ on agent, "test -L #{target} && test -f #{target}"
+ step "verify source file"
+ on agent, "test -f #{source}"
+
+ step "verify the content is identical on both sides"
+ on(agent, "cat #{source}") do
fail_test "source missing content" unless stdout.include? message
-end
-on(agents, "cat #{target}") do
+ end
+ on(agent, "cat #{target}") do
fail_test "target missing content" unless stdout.include? message
-end
+ end
-step "clean up after the test run"
-on agents, "rm -rf #{target} #{source}"
+ step "clean up after the test run"
+ on agent, "rm -rf #{target} #{source}"
+end
View
28 acceptance/tests/resource/file/should_remove_dir.rb
@@ -1,21 +1,23 @@
test_name "should remove directory, but force required"
-target = "/tmp/test-#{Time.new.to_i}"
+agents.each do |agent|
+ target = agent.tmpdir("delete-dir")
-step "clean up the system before we begin"
-on agents, "rm -rf #{target} ; mkdir -p #{target}"
+ step "clean up the system before we begin"
+ on agent, "rm -rf #{target} ; mkdir -p #{target}"
-step "verify we can't remove a directory without 'force'"
-on(agents, puppet_resource("file", target, 'ensure=absent')) do
+ step "verify we can't remove a directory without 'force'"
+ on(agent, puppet_resource("file", target, 'ensure=absent')) do
fail_test "didn't tell us that force was required" unless
- stdout.include? "Not removing directory; use 'force' to override"
-end
+ stdout.include? "Not removing directory; use 'force' to override"
+ end
-step "verify the directory still exists"
-on agents, "test -d #{target}"
+ step "verify the directory still exists"
+ on agent, "test -d #{target}"
-step "verify we can remove a directory with 'force'"
-on(agents, puppet_resource("file", target, 'ensure=absent', 'force=true'))
+ step "verify we can remove a directory with 'force'"
+ on(agent, puppet_resource("file", target, 'ensure=absent', 'force=true'))
-step "verify that the directory is gone"
-on agents, "test -d #{target}", :acceptable_exit_codes => [1]
+ step "verify that the directory is gone"
+ on agent, "test -d #{target}", :acceptable_exit_codes => [1]
+end
View
16 acceptance/tests/resource/file/should_remove_file.rb
@@ -1,12 +1,14 @@
test_name "should remove file"
-target = "/tmp/test-#{Time.new.to_i}"
+agents.each do |agent|
+ target = agent.tmpfile('delete-file')
-step "clean up the system before we begin"
-on agents, "rm -rf #{target} && touch #{target}"
+ step "clean up the system before we begin"
+ on agent, "rm -rf #{target} && touch #{target}"
-step "verify we can remove a file"
-on(agents, puppet_resource("file", target, 'ensure=absent'))
+ step "verify we can remove a file"
+ on(agent, puppet_resource("file", target, 'ensure=absent'))
-step "verify that the file is gone"
-on agents, "test -e #{target}", :acceptable_exit_codes => [1]
+ step "verify that the file is gone"
+ on agent, "test -e #{target}", :acceptable_exit_codes => [1]
+end
View
55 acceptance/tests/resource/file/source_attribtute.rb
@@ -1,43 +1,46 @@
test_name "The source attribute"
-step "Ensure the test environment is clean"
-on agents, 'rm -f /tmp/source_file_test.txt'
+agents.each do |agent|
+ target = agent.tmpfile('source_file_test')
+
+ step "Ensure the test environment is clean"
+ on agent, "rm -f #{target}"
# TODO: Add tests for puppet:// URIs with master/agent setups.
# step "when using a puppet:/// URI with a master/agent setup"
# step "when using a puppet://$server/ URI with a master/agent setup"
-step "Using a local file path"
-on agents, "echo 'Yay, this is the local file.' > /tmp/local_source_file_test.txt"
-manifest = "file { '/tmp/source_file_test.txt': source => '/tmp/local_source_file_test.txt', ensure => present }"
+ step "Using a local file path"
+ source = agent.tmpfile('local_source_file_test')
+ on agent, "echo 'Yay, this is the local file.' > #{source}"
-apply_manifest_on agents, manifest
-agents.each do |host|
- on host, "cat /tmp/source_file_test.txt" do
- assert_match(/Yay, this is the local file./, stdout, "FIRST: File contents not matched on #{host}")
+ manifest = "file { '#{target}': source => '#{source}', ensure => present }"
+ apply_manifest_on agent, manifest
+ on agent, "cat #{target}" do
+ assert_match(/Yay, this is the local file./, stdout, "FIRST: File contents not matched on #{agent}")
end
-end
-
-step "Ensure the test environment is clean"
-on agents, 'rm -f /tmp/source_file_test.txt'
-step "Using a puppet:/// URI with puppet apply"
+ step "Ensure the test environment is clean"
+ on agent, "rm -f #{target}"
-on agents, puppet_agent("--configprint modulepath") do
- modulepath = stdout.split(':')[0]
- modulepath = modulepath.chomp
- on agents, "mkdir -p #{modulepath}/test_module/files"
- #on agents, "echo 'Yay, this is the puppet:/// file.' > #{modulepath}/test_module/files/test_file.txt"
- on agents, "echo 'Yay, this is the puppetfile.' > #{modulepath}/test_module/files/test_file.txt"
-end
+ step "Using a puppet:/// URI with puppet apply"
+ on agent, puppet_agent("--configprint modulepath") do
+ modulepath = agent.path_split(stdout)[0]
+ modulepath = modulepath.chomp
+ on agent, "mkdir -p '#{modulepath}/test_module/files'"
+ #on agent, "echo 'Yay, this is the puppet:/// file.' > #{modulepath}/test_module/files/test_file.txt"
+ on agent, "echo 'Yay, this is the puppetfile.' > '#{modulepath}/test_module/files/test_file.txt'"
+ end
-on agents, %q{echo "file { '/tmp/source_file_test.txt': source => 'puppet:///modules/test_module/test_file.txt', ensure => present }" > /tmp/source_test_manifest.pp}
-on agents, puppet_apply("/tmp/source_test_manifest.pp")
+ manifest = "file { '#{target}': source => 'puppet:///modules/test_module/test_file.txt', ensure => present }"
+ apply_manifest_on agent, manifest
-agents.each do |host|
- on host, "cat /tmp/source_file_test.txt" do
- assert_match(/Yay, this is the puppetfile./, stdout, "SECOND: File contents not matched on #{host}")
+ on agent, "cat #{target}" do
+ assert_match(/Yay, this is the puppetfile./, stdout, "SECOND: File contents not matched on #{agent}")
end
+
+ step "Cleanup"
+ on agent, "rm -f #{target}; rm -rf #{source}"
end
# Oops. We (Jesse & Jacob) ended up writing this before realizing that you
View
49 acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb
@@ -2,31 +2,38 @@
target = "/test-socket-#{$$}"
-step "clean up the system before we begin"
-on(agents, "rm -f #{target}")
+agents.each do |agent|
+ if agent['platform'].include?('windows')
+ skip_test "Test not supported on this platform"
+ next
+ end
-step "create UNIX domain socket"
-on(agents, %Q{ruby -e "require 'socket'; UNIXServer::new('#{target}').close"})
+ step "clean up the system before we begin"
+ on(agent, "rm -f #{target}")
-step "query for all files, which should return nothing"
-on(agents, puppet_resource('file'), :acceptable_exit_codes => [1]) do
- assert_match(%r{Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc}, stderr)
-end
+ step "create UNIX domain socket"
+ on(agent, %Q{ruby -e "require 'socket'; UNIXServer::new('#{target}').close"})
+
+ step "query for all files, which should return nothing"
+ on(agent, puppet_resource('file'), :acceptable_exit_codes => [1]) do
+ assert_match(%r{Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc}, stderr)
+ end
-["/", "/etc"].each do |file|
- step "query '#{file}' directory, which should return single entry"
- on(agents, puppet_resource('file', file)) do
- files = stdout.scan(/^file \{ '([^']+)'/).flatten
+ ["/", "/etc"].each do |file|
+ step "query '#{file}' directory, which should return single entry"
+ on(agent, puppet_resource('file', file)) do
+ files = stdout.scan(/^file \{ '([^']+)'/).flatten
- assert_equal(1, files.size, "puppet returned multiple files: #{files.join(', ')}")
- assert_match(file, files[0], "puppet did not return file")
+ assert_equal(1, files.size, "puppet returned multiple files: #{files.join(', ')}")
+ assert_match(file, files[0], "puppet did not return file")
+ end
end
-end
-step "query file that does not exist, which should report the file is absent"
-on(agents, puppet_resource('file', '/this/does/notexist')) do
- assert_match(/ensure\s+=>\s+'absent'/, stdout)
-end
+ step "query file that does not exist, which should report the file is absent"
+ on(agent, puppet_resource('file', '/this/does/notexist')) do
+ assert_match(/ensure\s+=>\s+'absent'/, stdout)
+ end
-step "remove UNIX domain socket"
-on(agents, "rm -f #{target}")
+ step "remove UNIX domain socket"
+ on(agent, "rm -f #{target}")
+end

0 comments on commit 41e91d8

Please sign in to comment.