From ba0d0fed55d872efa0aa9ad886fd1012cdfb7bc9 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Dec 2024 13:03:53 +0100 Subject: [PATCH] Added acceptance test for CFE-2216 Added acceptance test for testing that files converted to directories should be changed back to files on recusive copy. The test is currently set to soft fail. Ticket: CFE-2216 Changelog: None Signed-off-by: Lars Erik Wik --- .../acceptance/10_files/copy_from_convert.cf | 88 +++++++++++++++++++ .../10_files/copy_from_convert.cf.template | 29 ++++++ 2 files changed, 117 insertions(+) create mode 100644 tests/acceptance/10_files/copy_from_convert.cf create mode 100644 tests/acceptance/10_files/copy_from_convert.cf.template diff --git a/tests/acceptance/10_files/copy_from_convert.cf b/tests/acceptance/10_files/copy_from_convert.cf new file mode 100644 index 0000000000..786f498b67 --- /dev/null +++ b/tests/acceptance/10_files/copy_from_convert.cf @@ -0,0 +1,88 @@ +############################################################ +# CFE-2216: Files converted to directories should be changed +# back on recursive copy +############################################################ + +body common control +{ + bundlesequence => { "init", "test", "check", "clean" }; + version => "1.0"; +} + +bundle common G { + vars: + "testdir" + string => concat( + getenv("TEMP", "65535"), + "$(const.dirsep)TESTDIR.cfengine" + ); +} + +body delete tidy +{ + dirlinks => "delete"; + rmdirs => "true"; +} + +body contain use_shell +{ + useshell => "useshell"; +} + +############################################################ + +bundle agent init +{ + files: + "$(G.testdir)/src/." + create => "true"; + "$(G.testdir)/src/foo" + content => "Hello CFEngine!"; + "$(this.promise_filename).sub" + create => "true", + edit_template => "$(this.promise_filename).template", + template_method => "mustache", + template_data => parsejson('{ "testdir": "$(G.testdir)" }'); +} + +############################################################ + +bundle agent test +{ + meta: + "description" -> { "CFE-2216" } + string => "Files converted to directories should be changed back on recursive copy"; + "test_soft_fail" + string => "any", + meta => { "CFE-2216" }; + + commands: + "$(sys.cf_agent) -Kf $(this.promise_filename).sub"; + "rm $(G.testdir)/dst/foo && sudo mkdir $(G.testdir)/dst/foo" + contain => use_shell; + "$(sys.cf_agent) -Kf $(this.promise_filename).sub --"; +} + +############################################################ + +bundle agent check +{ + classes: + "ok" + expression => not(isdir("$(G.testdir)/dst/foo")); + + reports: + ok:: + "$(this.promise_filename) Pass"; + !ok:: + "$(this.promise_filename) FAIL"; +} + +bundle agent clean +{ + files: + "$(this.promise_filename).sub" + delete => tidy; + "$(this.promise_filename).sub.cf-before-edit" + delete => tidy; +} diff --git a/tests/acceptance/10_files/copy_from_convert.cf.template b/tests/acceptance/10_files/copy_from_convert.cf.template new file mode 100644 index 0000000000..a5f7efed22 --- /dev/null +++ b/tests/acceptance/10_files/copy_from_convert.cf.template @@ -0,0 +1,29 @@ +############################################################ +# CFE-2216: Files converted to directories should be changed +# back on recursive copy +############################################################ + +bundle common G { + vars: + "testdir" + string => "{{testdir}}"; +} + +body depth_search recurse { + depth => "inf"; + xdev => "true"; +} + +body copy_from source_dir { + source => "$(G.testdir)/src"; + compare => "digest"; +} + +bundle agent main +{ + files: + "$(G.testdir)/dst" + copy_from => source_dir, + move_obstructions => "true", + depth_search => recurse; +}