From: <jh...@us...> - 2010-01-20 23:05:13
|
Revision: 192 http://etch.svn.sourceforge.net/etch/?rev=192&view=rev Author: jheiss Date: 2010-01-20 23:05:05 +0000 (Wed, 20 Jan 2010) Log Message: ----------- Rename all of the files with tests to match what Rake::TestTask expects by default, allowing us to clean up the Rakefile a bit. Modified Paths: -------------- trunk/Rakefile Added Paths: ----------- trunk/test/test_actions.rb trunk/test/test_attributes.rb trunk/test/test_auth.rb trunk/test/test_commands.rb trunk/test/test_delete.rb trunk/test/test_depend.rb trunk/test/test_file.rb trunk/test/test_history.rb trunk/test/test_link.rb trunk/test/test_local_requests.rb trunk/test/test_nodegroups.rb trunk/test/test_options.rb trunk/test/test_outputcapture.rb trunk/test/test_scripts.rb trunk/test/test_transitions.rb Removed Paths: ------------- trunk/test/actions.rb trunk/test/attributes.rb trunk/test/auth.rb trunk/test/commands.rb trunk/test/delete.rb trunk/test/depend.rb trunk/test/file.rb trunk/test/history.rb trunk/test/link.rb trunk/test/local_requests.rb trunk/test/nodegroups.rb trunk/test/options.rb trunk/test/outputcapture.rb trunk/test/scripts.rb trunk/test/transitions.rb Modified: trunk/Rakefile =================================================================== --- trunk/Rakefile 2010-01-20 22:43:55 UTC (rev 191) +++ trunk/Rakefile 2010-01-20 23:05:05 UTC (rev 192) @@ -9,6 +9,4 @@ end t.verbose = true - #t.pattern = 'test/*.rb' - t.test_files = Dir.glob('test/*.rb').reject {|test| test =~ /etchtest.rb/} end Deleted: trunk/test/actions.rb =================================================================== --- trunk/test/actions.rb 2010-01-20 22:43:55 UTC (rev 191) +++ trunk/test/actions.rb 2010-01-20 23:05:05 UTC (rev 192) @@ -1,472 +0,0 @@ -#!/usr/bin/ruby -w - -# -# Test etch's handling of various actions: pre, post, setup, test, etc. -# - -require File.join(File.dirname(__FILE__), 'etchtest') - -class EtchActionTests < Test::Unit::TestCase - include EtchTests - - def setup - # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path - #puts "Using #{@targetfile} as target file" - - # Generate a directory for our test repository - @repodir = initialize_repository - @server = get_server(@repodir) - - # Create a directory to use as a working directory for the client - @testbase = tempdir - #puts "Using #{@testbase} as client working directory" - - # Generate another file to use as our link target - @destfile = Tempfile.new('etchtest').path - #puts "Using #{@destfile} as link destination file" - end - - def test_actions - - # - # Basic tests to ensure that actions are performed under normal - # circumstances - # - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <server_setup> - <exec>echo server_setup >> #{@repodir}/server_setup</exec> - </server_setup> - <setup> - <exec>echo setup >> #{@repodir}/setup</exec> - </setup> - <pre> - <exec>echo pre >> #{@repodir}/pre</exec> - </pre> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - <test_before_post> - <exec>echo test_before_post >> #{@repodir}/test_before_post</exec> - </test_before_post> - <post> - <exec_once>echo exec_once >> #{@repodir}/exec_once</exec_once> - <exec_once_per_run>echo exec_once_per_run >> #{@repodir}/exec_once_per_run</exec_once_per_run> - <exec_once_per_run>echo exec_once_per_run >> #{@repodir}/exec_once_per_run</exec_once_per_run> - <exec>echo post >> #{@repodir}/post</exec> - </post> - <test> - <exec>echo test >> #{@repodir}/test</exec> - </test> - </config> - EOF - end - - sourcecontents = "This is a test\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running initial action test" - run_etch(@server, @testbase) - - # Verify that the actions were executed - # The setup actions will get run several times as we loop - # back and forth with the server sending original sums and - # contents. So just verify that they were run at least once. - assert_match("server_setup\n", get_file_contents("#{@repodir}/server_setup"), 'server_setup') - assert_match("setup\n", get_file_contents("#{@repodir}/setup"), 'setup') - assert_equal("pre\n", get_file_contents("#{@repodir}/pre"), 'pre') - assert_equal( - "exec_once\n", get_file_contents("#{@repodir}/exec_once"), 'exec_once') - assert_equal( - "exec_once_per_run\n", - get_file_contents("#{@repodir}/exec_once_per_run"), - 'exec_once_per_run') - assert_equal( - "test_before_post\n", - get_file_contents("#{@repodir}/test_before_post"), - 'test_before_post') - assert_equal("post\n", get_file_contents("#{@repodir}/post"), 'post') - assert_equal("test\n", get_file_contents("#{@repodir}/test"), 'test') - - # Run etch again and make sure that the exec_once command wasn't run - # again - run_etch(@server, @testbase) - - assert_equal("exec_once\n", get_file_contents("#{@repodir}/exec_once"), 'exec_once_2nd_check') - end - - def test_failed_setup - # - # Test a failed setup command to ensure etch aborts - # - - # Put some text into the original file so that we can make sure it - # is not touched. - origcontents = "This is the original text\n" - File.delete(@targetfile) - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <setup> - <exec>false</exec> - </setup> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "This is a test\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running initial action test" - run_etch(@server, @testbase, true) - - # Verify that the file was not touched - assert_equal(origcontents, get_file_contents(@targetfile), 'failed setup') - end - - def test_failed_pre - # - # Test a failed pre command to ensure etch aborts - # - - # Put some text into the original file so that we can make sure it - # is not touched. - origcontents = "This is the original text\n" - File.delete(@targetfile) - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <pre> - <exec>false</exec> - </pre> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "This is a test\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running failed pre test" - run_etch(@server, @testbase, true) - - # Verify that the file was not touched - assert_equal(origcontents, get_file_contents(@targetfile), 'failed pre') - end - - def test_failed_test - # - # Run a test where the test action fails, ensure that the original - # target file is restored and any post actions re-run afterwards - # - - # Put some text into the original file so that we can make sure it - # is restored. - origcontents = "This is the original text\n" - File.delete(@targetfile) - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <overwrite_directory/> - <source> - <plain>source</plain> - </source> - </file> - <post> - <exec>echo post >> #{@repodir}/post</exec> - </post> - <test> - <exec>false</exec> - </test> - </config> - EOF - end - - # Change the source file so that we can see whether the original was - # restored or not - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write("Testing a failed test\n") - end - - # Run etch - #puts "Running failed test test" - run_etch(@server, @testbase) - - # Verify that the original was restored, and that post was run twice - assert_equal(origcontents, get_file_contents(@targetfile), 'failed test target') - assert_equal("post\npost\n", get_file_contents("#{@repodir}/post"), 'failed test post') - end - - def test_failed_test_before_post - # - # Run a test where the test_before_post action fails, ensure that - # post is not run - # - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <overwrite_directory/> - <source> - <plain>source</plain> - </source> - </file> - <test_before_post> - <exec>false</exec> - </test_before_post> - <post> - <exec>echo post >> #{@repodir}/post</exec> - </post> - </config> - EOF - end - - # Run etch - #puts "Running failed test_before_post test" - run_etch(@server, @testbase, true) - - # Verify that post was not run - assert(!File.exist?("#{@repodir}/post"), 'failed test_before_post post') - - # - # Run a test where the test action fails, and the original target file - # is a symlink. Ensure that the symlink is restored. - # - - # Prepare the target - File.delete(@targetfile) if File.exist?(@targetfile) - File.symlink(@destfile, @targetfile) - - # Run etch - #puts "Running failed test symlink test" - run_etch(@server, @testbase, true) - - # Verify that the original symlink was restored - assert_equal(@destfile, File.readlink(@targetfile), 'failed test symlink') - - # - # Run a test where the test action fails, and the original target file - # is a directory. Ensure that the directory is restored. - # - - # Prepare the target - File.delete(@targetfile) if File.exist?(@targetfile) - Dir.mkdir(@targetfile) - File.open("#{@targetfile}/testfile", 'w') { |file| } - - # Run etch - #puts "Running failed test directory test" - run_etch(@server, @testbase, true) - - # Verify that the original directory was restored - assert(File.directory?(@targetfile), 'failed test directory') - assert(File.file?("#{@targetfile}/testfile"), 'failed test directory contents') - - # - # Run a test where the test action fails, and there is no original - # target file. Ensure that the end result is that there is no file left - # behind. - # - - # We can reuse the config.xml from the previous test - - # Clean up from previous runs - if File.exist?(@targetfile) || File.symlink?(@targetfile) - FileUtils.rm_rf(@targetfile) - end - File.delete("#{@repodir}/post") if File.exist?("#{@repodir}/post") - - # Run etch - #puts "Running failed test no original file test" - run_etch(@server, @testbase, true) - - # Verify that the lack of an original file was restored - assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), 'failed test no original file') - end - - def test_nested_target - # - # Run a test where a test action is defined and the target file is in a - # directory that does not exist yet, thus requiring that we make the - # directory before creating the backup (or rather the NOORIG marker in - # this case). We had a bug where that failed, as the code to make the - # directory structure was after the code to make the backup. - # - # I.e. configuration to create /etc/foo/bar, but /etc/foo does not exist. - # The backup that is created when a test is defined (so that we can roll - # back if the test fails) is made as /etc/foo/bar.XXXXX, which requires - # that /etc/foo exist first. - # - - nestedtargetdir = Tempfile.new('etchtest').path - File.delete(nestedtargetdir) - nestedtargetfile = File.join(nestedtargetdir, 'etchnestedtest') - - FileUtils.mkdir_p("#{@repodir}/source/#{nestedtargetfile}") - File.open("#{@repodir}/source/#{nestedtargetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - <test> - <exec>true</exec> - </test> - </config> - EOF - end - - sourcecontents = "Testing a nested target\n" - File.open("#{@repodir}/source/#{nestedtargetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running nested target with test test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(nestedtargetfile), 'nested target with test') - end - - def test_action_with_xml_escape - # - # Test an action requiring XML escape - # The XML spec says that < and & must be escaped almost anywhere - # outside of their use as markup. That includes the character data of - # actions. - # http://www.w3.org/TR/2006/REC-xml-20060816/#syntax - # So if the user wants to use something like && in an action they must - # escape the & with & - # - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - <post> - <exec>true && echo post >> #{@repodir}/post_with_escape</exec> - </post> - </config> - EOF - end - - sourcecontents = "This is a test of a post with XML escapes\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running XML escape test" - run_etch(@server, @testbase) - - # Verify that the action was executed - assert_equal("post\n", get_file_contents("#{@repodir}/post_with_escape"), 'post with escape') - end - - def test_action_with_env - # - # Test an action involving passing an environment variable - # - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - <post> - <exec>TESTVAR=testvalue #{@repodir}/post_with_env</exec> - </post> - </config> - EOF - end - - sourcecontents = "This is a test of a post with an environment variable\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - File.open("#{@repodir}/post_with_env", 'w') do |file| - file.write <<EOF -#!/bin/sh -echo $TESTVAR >> #{@repodir}/post_with_env_output -EOF - end - File.chmod(0755, "#{@repodir}/post_with_env") - - # Run etch - #puts "Running environment variable test" - run_etch(@server, @testbase) - - # Verify that the action was executed - assert_equal("testvalue\n", get_file_contents("#{@repodir}/post_with_env_output"), 'post with environment variable') - end - - def teardown - remove_repository(@repodir) - FileUtils.rm_rf(@testbase) - FileUtils.rm_rf(@targetfile) - FileUtils.rm_f(@destfile) - end -end Deleted: trunk/test/attributes.rb =================================================================== --- trunk/test/attributes.rb 2010-01-20 22:43:55 UTC (rev 191) +++ trunk/test/attributes.rb 2010-01-20 23:05:05 UTC (rev 192) @@ -1,633 +0,0 @@ -#!/usr/bin/ruby -w - -# -# Test etch's handling of attribute filtering in config.xml files -# - -require File.join(File.dirname(__FILE__), 'etchtest') -require 'rubygems' # Might be needed to find facter -require 'facter' - -class EtchAttributeTests < Test::Unit::TestCase - include EtchTests - - def setup - # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path - #puts "Using #{@targetfile} as target file" - - # Generate a directory for our test repository - @repodir = initialize_repository - @server = get_server(@repodir) - - # Create a directory to use as a working directory for the client - @testbase = tempdir - #puts "Using #{@testbase} as client working directory" - end - - def test_group_attributes - # - # Simple group name comparison with the node in 0 groups - # - testname = 'node group comparison, 0 groups' - - # Put some text into the original file so that we can make sure it is - # not touched. - origcontents = "This is the original text\n" - File.chmod(0644, @targetfile) - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain group="testgroup">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was not modified - assert_equal(origcontents, get_file_contents(@targetfile), testname) - - # - # Negate the simple group name comparison with the node in 0 groups - # - testname = 'negate node group comparison, 0 groups' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain group="!testgroup">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - # - # Put the node in one group for the next series of tests - # - hostname = `facter fqdn`.chomp - File.open(File.join(@repodir, 'nodes.xml'), 'w') do |file| - file.puts <<-EOF - <nodes> - <node name="#{hostname}"> - <group>testgroup</group> - </node> - </nodes> - EOF - end - - # - # Simple group name comparison with the node in 1 group - # - testname = 'node group comparison, 1 group' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain group="testgroup">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - # - # Negate the simple group name comparison with the node in 1 group - # - testname = 'negate node group comparison, 1 group' - - # Put some text into the original file so that we can make sure it is - # not touched. - origcontents = "This is the original text\n" - File.chmod(0644, @targetfile) - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain group="!testgroup">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was not modified - assert_equal(origcontents, get_file_contents(@targetfile), testname) - - # - # Regex group name comparison with the node in 1 group - # - testname = 'regex node group comparison, 1 group' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain group="/test/">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - # - # Put the node in two groups for the next series of tests - # - hostname = `facter fqdn`.chomp - File.open(File.join(@repodir, 'nodes.xml'), 'w') do |file| - file.puts <<-EOF - <nodes> - <node name="#{hostname}"> - <group>testgroup</group> - <group>second</group> - </node> - </nodes> - EOF - end - - # - # Simple group name comparison with the node in 2 groups - # - testname = 'node group comparison, 2 groups' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain group="testgroup">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - # - # Negate the simple group name comparison with the node in 2 groups - # - testname = 'negate node group comparison, 2 groups' - - # Put some text into the original file so that we can make sure it is - # not touched. - origcontents = "This is the original text\n" - File.chmod(0644, @targetfile) - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain group="!testgroup">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was not modified - assert_equal(origcontents, get_file_contents(@targetfile), testname) - - # - # Regex group name comparison with the node in 2 groups - # - testname = 'regex node group comparison, 2 groups' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain group="/test/">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - end - - def test_fact_attributes - Facter.loadfacts - os = Facter['operatingsystem'].value - # Facter frequently leaves extraneous whitespace on this fact, thus - # the strip - osrel = Facter['operatingsystemrelease'].value.strip - - # - # Simple fact comparison - # - testname = 'fact comparison' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain operatingsystem="#{os}">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - # - # Negate fact comparison - # - testname = 'negate fact comparison' - - # Put some text into the original file so that we can make sure it is - # not touched. - origcontents = "This is the original text\n" - File.chmod(0644, @targetfile) - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain operatingsystem="!#{os}">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was not modified - assert_equal(origcontents, get_file_contents(@targetfile), testname) - - # - # Regex fact comparison - # - testname = 'regex fact comparison' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain operatingsystem="/#{os[0,2]}/">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - # - # Negate regex fact comparison - # - testname = 'negate regex fact comparison' - - # Put some text into the original file so that we can make sure it is - # not touched. - origcontents = "This is the original text\n" - File.chmod(0644, @targetfile) - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain operatingsystem="!/#{os[0,2]}/">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was not modified - assert_equal(origcontents, get_file_contents(@targetfile), testname) - - # - # Version fact operator comparison - # - testname = 'version fact operator comparison' - - # Try to make up a subset of operatingsystemrelease so that we really - # test the operator functionality and not just equality. I.e. if osrel - # is 2.5.1 we'd like to extract 2.5 - osrelsubset = osrel - osrelparts = osrel.split('.') - if osrelparts.length > 1 - osrelparts.pop - osrelsubset = osrelparts.join('.') - end - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain operatingsystemrelease=">=#{osrelsubset}">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - # - # Negate version fact operator comparison - # - testname = 'negate fact comparison' - - # Put some text into the original file so that we can make sure it is - # not touched. - origcontents = "This is the original text\n" - File.chmod(0644, @targetfile) - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain operatingsystemrelease="!>=#{osrel}">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was not modified - assert_equal(origcontents, get_file_contents(@targetfile), testname) - - # - # Version fact operator comparison requiring XML escape - # The XML spec says that < and & must be escaped almost anywhere - # outside of their use as markup. That includes inside attribute values. - # http://www.w3.org/TR/2006/REC-xml-20060816/#syntax - # So if the user wants to use the < or <= operators they must escape - # the < with < - # - testname = 'version fact operator comparison requiring XML escape' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain operatingsystemrelease="<=#{osrel}">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - # - # Multiple fact comparison - # - testname = 'multiple fact comparison' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain operatingsystem="#{os}" operatingsystemrelease="#{osrel}">source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - end - - def teardown - remove_repository(@repodir) - FileUtils.rm_rf(@testbase) - FileUtils.rm_rf(@targetfile) - end -end - Deleted: trunk/test/auth.rb =================================================================== --- trunk/test/auth.rb 2010-01-20 22:43:55 UTC (rev 191) +++ trunk/test/auth.rb 2010-01-20 23:05:05 UTC (rev 192) @@ -1,258 +0,0 @@ -#!/usr/bin/ruby -w - -# -# Test etch's handling of client authentication -# - -require File.join(File.dirname(__FILE__), 'etchtest') -require 'net/http' -require 'rexml/document' -require 'facter' - -class EtchAuthTests < Test::Unit::TestCase - include EtchTests - - def setup - # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path - #puts "Using #{@targetfile} as target file" - - # Generate a directory for our test repository - @repodir = initialize_repository - # These tests set an etchserver.conf. The server only reads that file - # once and caches the settings, so we need to start up new server - # instances for these tests rather than reusing the global test server. - @server = start_server(@repodir) - - # Create a directory to use as a working directory for the client - @testbase = tempdir - #puts "Using #{@testbase} as client working directory" - - # Make sure the server will initially think this is a new client - hostname = Facter['fqdn'].value - Net::HTTP.start('localhost', @server[:port]) do |http| - # Find our client id - response = http.get("/clients.xml?name=#{hostname}") - if !response.kind_of?(Net::HTTPSuccess) - response.error! - end - response_xml = REXML::Document.new(response.body) - client_id = nil - if response_xml.elements['/clients/client/id'] - client_id = response_xml.elements['/clients/client/id'].text - end - # Delete our client entry - if client_id - response = http.delete("/clients/#{client_id}.xml") - if !response.kind_of?(Net::HTTPSuccess) - response.error! - end - end - end - end - - # Test authentication when new clients are allowed - def test_auth_allow_new_clients - File.open(File.join(@repodir, 'etchserver.conf'), 'w') do |file| - file.puts 'auth_enabled=true' - file.puts 'auth_deny_new_clients=false' - end - - # - # New client, should work - # - testname = 'auth, allow new clients, new client' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - # - # Existing client, should work - # - testname = 'auth, allow new clients, existing client' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - - # - # Existing client, bad signature, should be denied - # - testname = 'auth, allow new clients, existing client, bad signature' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Put some text into the original file so that we can make sure it - # is not touched. - origcontents = "This is the original text\n" - File.delete(@targetfile) - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - # Run etch with the wrong key to force a bad signature - #puts "Running '#{testname}' test" - run_etch(@server, @testbase, true, "--key=#{File.join(File.dirname(__FILE__), 'keys', 'testkey2')}") - - # Verify that the file was not touched - assert_equal(origcontents, get_file_contents(@targetfile), testname) - end - # Test authentication when new clients are denied - def test_auth_deny_new_clients - File.open(File.join(@repodir, 'etchserver.conf'), 'w') do |file| - file.puts 'auth_enabled=true' - file.puts 'auth_deny_new_clients=true' - end - - # - # New client, should fail - # - testname = 'auth, deny new clients, new client' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Put some text into the original file so that we can make sure it - # is not touched. - origcontents = "This is the original text\n" - File.open(@targetfile, 'w') do |file| - file.write(origcontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase, true) - - # Verify that the file was not touched - assert_equal(origcontents, get_file_contents(@targetfile), testname) - - # - # Add this client to the server so that it will now be considered - # an existing client - # - puts "# Starting a second copy of the server and adding this client to the database" - sleep 3 - repodir2 = initialize_repository - server2 = start_server(repodir2) - run_etch(server2, @testbase) - stop_server(server2) - remove_repository(repodir2) - - # - # Existing client, should work - # - testname = 'auth, deny new clients, existing client' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - </config> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(sourcecontents, get_file_contents(@targetfile), testname) - end - - def teardown - stop_server(@server) - remove_repository(@repodir) - FileUtils.rm_rf(@testbase) - FileUtils.rm_rf(@targetfile) - end -end - Deleted: trunk/test/commands.rb =================================================================== --- trunk/test/commands.rb 2010-01-20 22:43:55 UTC (rev 191) +++ trunk/test/commands.rb 2010-01-20 23:05:05 UTC (rev 192) @@ -1,375 +0,0 @@ -#!/usr/bin/ruby -w - -# -# Test etch's handling of configuration commands -# - -require File.join(File.dirname(__FILE__), 'etchtest') - -class EtchCommandTests < Test::Unit::TestCase - include EtchTests - - def setup - # Generate a file to use as a target in commands - @targetfile = Tempfile.new('etchtest').path - #puts "Using #{@targetfile} as target file" - - # Generate a directory for our test repository - @repodir = initialize_repository - @server = get_server(@repodir) - - # Create a directory to use as a working directory for the client - @testbase = tempdir - #puts "Using #{@testbase} as client working directory" - end - - def test_commands_basic - # - # Guard initially fails, command fixes it - # - testname = 'guard initially fails, command fixes it' - - FileUtils.mkdir_p("#{@repodir}/commands/etchtest") - File.open("#{@repodir}/commands/etchtest/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <step> - <guard> - <exec>grep '#{testname}' #{@targetfile}</exec> - </guard> - <command> - <exec>printf '#{testname}' >> #{@targetfile}</exec> - </command> - </step> - </commands> - EOF - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was created properly - assert_equal(testname, get_file_contents(@targetfile), testname) - end - - def test_commands_failure - # - # Guard initially fails, command doesn't fix it - # - testname = 'guard initially fails, command doesnt fix it' - - FileUtils.mkdir_p("#{@repodir}/commands/etchtest") - File.open("#{@repodir}/commands/etchtest/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <step> - <guard> - <exec>grep '#{testname}' #{@targetfile}</exec> - </guard> - <command> - <exec>echo '#{testname}'</exec> - </command> - </step> - </commands> - EOF - end - - # Run etch - # The assertion here is handled by run_etch as we're passing it an - # argument indicating that we expect failure. - #puts "Running '#{testname}' test" - run_etch(@server, @testbase, true) - end - - def test_commands_guard_succeeds - # - # Guard initially succeeds - # - testname = 'guard initially succeeds' - - FileUtils.mkdir_p("#{@repodir}/commands/etchtest") - File.open("#{@repodir}/commands/etchtest/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <step> - <guard> - <exec>grep '#{testname}' #{@targetfile}</exec> - </guard> - <command> - <exec>echo failure >> #{@targetfile}</exec> - </command> - </step> - </commands> - EOF - end - - File.open(@targetfile, 'w') { |file| file.print(testname) } - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was not touched - assert_equal(testname, get_file_contents(@targetfile), testname) - end - - def test_commands_multiple_steps - # - # Multiple steps - # - testname = 'multiple steps' - - FileUtils.mkdir_p("#{@repodir}/commands/etchtest") - File.open("#{@repodir}/commands/etchtest/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <step> - <guard> - <exec>grep firststep #{@targetfile}</exec> - </guard> - <command> - <exec>echo firststep >> #{@targetfile}</exec> - </command> - </step> - <step> - <guard> - <exec>grep secondstep #{@targetfile}</exec> - </guard> - <command> - <exec>echo secondstep >> #{@targetfile}</exec> - </command> - </step> - </commands> - EOF - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that both steps ran and in the proper order - assert_equal("firststep\nsecondstep\n", get_file_contents(@targetfile), testname) - end - - def test_commands_multiple_commands - # - # Multiple commands - # - testname = 'multiple commands' - - FileUtils.mkdir_p("#{@repodir}/commands/etchtest") - File.open("#{@repodir}/commands/etchtest/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <step> - <guard> - <exec>grep firstcmd #{@targetfile}</exec> - </guard> - <command> - <exec>echo firstcmd >> #{@targetfile}</exec> - </command> - </step> - </commands> - EOF - end - FileUtils.mkdir_p("#{@repodir}/commands/etchtest2") - File.open("#{@repodir}/commands/etchtest2/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <step> - <guard> - <exec>grep secondcmd #{@targetfile}</exec> - </guard> - <command> - <exec>echo secondcmd >> #{@targetfile}</exec> - </command> - </step> - </commands> - EOF - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that both commands ran, ordering doesn't matter - assert_equal(['firstcmd', 'secondcmd'], get_file_contents(@targetfile).split("\n").sort, testname) - end - - def test_commands_depend - # - # Multiple commands with dependency - # - testname = 'multiple commands with dependency' - - FileUtils.mkdir_p("#{@repodir}/commands/etchtest") - File.open("#{@repodir}/commands/etchtest/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <step> - <guard> - <exec>grep firstcmd #{@targetfile}</exec> - </guard> - <command> - <exec>echo firstcmd >> #{@targetfile}</exec> - </command> - </step> - </commands> - EOF - end - FileUtils.mkdir_p("#{@repodir}/commands/etchtest2") - File.open("#{@repodir}/commands/etchtest2/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <depend>etchtest</depend> - <step> - <guard> - <exec>grep secondcmd #{@targetfile}</exec> - </guard> - <command> - <exec>echo secondcmd >> #{@targetfile}</exec> - </command> - </step> - </commands> - EOF - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that both commands ran and in the proper order - assert_equal("firstcmd\nsecondcmd\n", get_file_contents(@targetfile), testname) - end - - def test_commands_dependfile - # - # Command with dependency on a file - # - testname = 'command with file dependency' - - targetfile2 = Tempfile.new('etchtest').path - FileUtils.mkdir_p("#{@repodir}/source/#{targetfile2}") - File.open("#{@repodir}/source/#{targetfile2}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <file> - <warning_file/> - <source> - <plain>source</plain> - </source> - </file> - <post> - <exec>sleep 3</exec> - </post> - </config> - EOF - end - - FileUtils.mkdir_p("#{@repodir}/commands/etchtest") - File.open("#{@repodir}/commands/etchtest/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <dependfile>#{targetfile2}</dependfile> - <step> - <guard> - <exec>grep '#{testname}' #{@targetfile}</exec> - </guard> - <command> - <exec>printf '#{testname}' >> #{@targetfile}</exec> - </command> - </step> - </commands> - EOF - end - - sourcecontents = "Test #{testname}\n" - File.open("#{@repodir}/source/#{targetfile2}/source", 'w') do |file| - file.write(sourcecontents) - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the command-generated file and the regular file were created - # properly - assert_equal(testname, get_file_contents(@targetfile), testname + ' command contents') - assert_equal(sourcecontents, get_file_contents(targetfile2), testname + ' file contents') - # And verify that they were created in the right order - assert(File.stat(@targetfile).mtime > File.stat(targetfile2).mtime, testname + ' ordering') - end - - def test_commands_filtering - # - # Attribute filtering - # Filtering of commands.xml uses the same methods as are used for the - # filtering of config.xml, which is heavily tested. So we just do a - # simple test to make sure that it basically works. - # - testname = 'command attribute filtering' - - FileUtils.mkdir_p("#{@repodir}/commands/etchtest") - File.open("#{@repodir}/commands/etchtest/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <step group="!testgroup"> - <guard> - <exec>grep notingroup #{@targetfile}</exec> - </guard> - <command> - <exec>echo notingroup >> #{@targetfile}</exec> - </command> - </step> - <step group="testgroup"> - <guard> - <exec>grep yesingroup #{@targetfile}</exec> - </guard> - <command> - <exec>echo yesingroup >> #{@targetfile}</exec> - </command> - </step> - </commands> - EOF - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that only the desired step executed - assert_equal("notingroup\n", get_file_contents(@targetfile), testname) - end - - def test_commands_dtd_failure - # - # commands.xml doesn't match DTD - # - testname = 'command DTD failure' - - FileUtils.mkdir_p("#{@repodir}/commands/etchtest") - File.open("#{@repodir}/commands/etchtest/commands.xml", 'w') do |file| - file.puts <<-EOF - <commands> - <step> - <bogus/> - </step> - </commands> - EOF - end - - # Run etch - # The assertion here is handled by run_etch as we're passing it an - # argument indicating that we expect failure. - #puts "Running '#{testname}' test" - run_etch(@server, @testbase, true) - end - - def teardown - remove_repository(@repodir) - FileUtils.rm_rf(@testbase) - FileUtils.rm_rf(@targetfile) - end -end - Deleted: trunk/test/delete.rb =================================================================== --- trunk/test/delete.rb 2010-01-20 22:43:55 UTC (rev 191) +++ trunk/test/delete.rb 2010-01-20 23:05:05 UTC (rev 192) @@ -1,237 +0,0 @@ -#!/usr/bin/ruby -w - -# -# Test etch's handling of deleting files -# - -require File.join(File.dirname(__FILE__), 'etchtest') - -class EtchDeleteTests < Test::Unit::TestCase - include EtchTests - - def setup - # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path - #puts "Using #{@targetfile} as target file" - - # Generate a directory for our test repository - @repodir = initialize_repository - @server = get_server(@repodir) - - # Create a directory to use as a working directory for the client - @testbase = tempdir - #puts "Using #{@testbase} as client working directory" - - # Generate another file to use as our link target - @destfile = Tempfile.new('etchtest').path - #puts "Using #{@destfile} as link destination file" - end - - def test_delete - - # - # Delete a file - # - testname = 'delete file' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <delete> - <proceed/> - </delete> - </config> - EOF - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the file was deleted - assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), testname) - - # - # Delete a link - # - testname = 'delete link' - - # Create the link - File.symlink(@destfile, @targetfile) - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <delete> - <proceed/> - </delete> - </config> - EOF - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the link was deleted - assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), testname) - - # - # Delete a directory - # - testname = 'delete directory w/o overwrite_directory' - - # Create the directory with a file inside just to make sure the - # delete handles that properly - Dir.mkdir(@targetfile) if (!File.directory?(@targetfile)) - File.open("#{@targetfile}/testfile", 'w') { |file| } - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <delete> - <proceed/> - </delete> - </config> - EOF - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase, true) - - # Verify that the directory was not deleted - assert(File.directory?(@targetfile), testname) - - # - # Delete a directory w/ overwrite_directory - # - testname = 'delete directory w/ overwrite_directory' - - # Create the directory with a file inside just to make sure the - # delete handles that properly - Dir.mkdir(@targetfile) if (!File.directory?(@targetfile)) - File.open("#{@targetfile}/testfile", 'w') { |file| } - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <delete> - <overwrite_directory/> - <proceed/> - </delete> - </config> - EOF - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that the directory was deleted - assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), testname) - - # - # Delete a non-existent file - # - testname = 'delete non-existent file' - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <delete> - <proceed/> - </delete> - </config> - EOF - end - - # Run etch - #puts "Running '#{testname}' test" - run_etch(@server, @testbase) - - # Verify that we still don't have a file. That's rather unlikely, - # this is really more a test that etch doesn't throw an error if - # told to delete something that doesn't exist, which is captured by - # the assert within run_etch. - assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), testname) - - # - # Test duplicate script instructions - # - - FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") - File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| - file.puts <<-EOF - <config> - <delete> - <script>source</script> - <script>source</script> - </delete> - </config> - EOF - end - - File.open(@targetfile, 'w') do |file| - file.puts('Original contents') - end - - File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| - file.puts("@contents << 'true'") - end - - # Run etch - #puts "Running duplicate script instructions test" - run_et... [truncated message content] |