Skip to content

Commit 6083b6c

Browse files
authored
Merge pull request #5661 from larsewi/convert
Added acceptance test for CFE-2216
2 parents f429c3b + c4ad149 commit 6083b6c

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
############################################################
2+
# CFE-2216: Files converted to directories should be changed
3+
# back on recursive copy
4+
############################################################
5+
6+
body common control
7+
{
8+
inputs => { "../default.cf.sub" };
9+
bundlesequence => { default("$(this.promise_filename)") };
10+
version => "1.0";
11+
}
12+
13+
############################################################
14+
15+
bundle agent init
16+
{
17+
files:
18+
"$(G.testdir)/src/."
19+
create => "true";
20+
"$(G.testdir)/src/foo"
21+
content => "Hello CFEngine!";
22+
"$(G.testdir)/src/bar/."
23+
create => "true";
24+
25+
# The .sub file needs to know the value of $(G.testdir). We can use a
26+
# template in order to hardcode it in before execution.
27+
"$(this.promise_filename).sub"
28+
create => "true",
29+
edit_template => "$(this.promise_filename).template",
30+
template_method => "mustache",
31+
template_data => parsejson('{ "testdir": "$(G.testdir)" }');
32+
}
33+
34+
############################################################
35+
36+
bundle agent test
37+
{
38+
meta:
39+
"description" -> { "CFE-2216" }
40+
string => "Files converted to directories should be changed back on recursive copy";
41+
42+
# This bug is not yet fixed, so we need to soft fail it
43+
"test_soft_fail"
44+
string => "any",
45+
meta => { "CFE-2216" };
46+
47+
commands:
48+
# Sync files between source and destination dir
49+
"$(sys.cf_agent) -Kf $(this.promise_filename).sub";
50+
51+
# Change foo from a file to a directory
52+
"rm $(G.testdir)/dst/foo && mkdir $(G.testdir)/dst/foo"
53+
contain => dcs_useshell;
54+
55+
# Change bar from a directory to a file
56+
"rmdir $(G.testdir)/dst/bar && touch $(G.testdir)/dst/bar"
57+
contain => dcs_useshell;
58+
59+
# Sync the files again. We append -- at the end to make sure the promise
60+
# hash is different
61+
"$(sys.cf_agent) -Kf $(this.promise_filename).sub --";
62+
}
63+
64+
############################################################
65+
66+
bundle agent check
67+
{
68+
classes:
69+
# Check that foo is converted back to a file and that bar is converted
70+
# back to a directory
71+
"ok"
72+
expression => and(
73+
not(isdir("$(G.testdir)/dst/foo")),
74+
isdir("$(G.testdir)/dst/bar")
75+
);
76+
77+
methods:
78+
""
79+
usebundle => dcs_passif("ok", "$(this.promise_filename)"),
80+
inherit => "true";
81+
}
82+
83+
############################################################
84+
85+
bundle agent clean
86+
{
87+
# Clean up the files generated from the template
88+
files:
89+
"$(this.promise_filename).sub"
90+
delete => tidy;
91+
"$(this.promise_filename).sub.cf-before-edit"
92+
delete => tidy;
93+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
############################################################
2+
# CFE-2216: Files converted to directories should be changed
3+
# back on recursive copy
4+
############################################################
5+
6+
bundle common G {
7+
vars:
8+
"testdir"
9+
string => "{{testdir}}";
10+
}
11+
12+
body depth_search recurse {
13+
depth => "inf";
14+
xdev => "true";
15+
}
16+
17+
body copy_from source_dir {
18+
source => "$(G.testdir)/src";
19+
compare => "digest";
20+
}
21+
22+
bundle agent main
23+
{
24+
files:
25+
"$(G.testdir)/dst"
26+
copy_from => source_dir,
27+
move_obstructions => "true",
28+
depth_search => recurse;
29+
}

0 commit comments

Comments
 (0)