Skip to content

Commit 56aac28

Browse files
committed
Added acceptance test for allow_non_convergent option in replace_pattern
Signed-off-by: Victor Moene <[email protected]>
1 parent 12b5eba commit 56aac28

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#######################################################
2+
#
3+
# Replace a pattern using non-convergent regexes
4+
#
5+
#######################################################
6+
7+
body common control
8+
{
9+
inputs => { "../../default.cf.sub" };
10+
bundlesequence => { default("$(this.promise_filename)") };
11+
version => "1.0";
12+
}
13+
14+
######################################################
15+
16+
bundle agent init
17+
{
18+
files:
19+
"/tmp/example.txt"
20+
content => "foo PORT=23 bar";
21+
22+
}
23+
24+
######################################################
25+
26+
bundle agent test
27+
{
28+
meta:
29+
"description" -> { "ENT-3417" }
30+
string => "Test that allow_non_convergent correctly replaces non-convergent regex";
31+
32+
files:
33+
"/tmp/example.txt"
34+
edit_line => _regex_replace( "PORT=[0-9]+", "PORT=22" );
35+
}
36+
37+
bundle edit_line _regex_replace(find,replace)
38+
{
39+
replace_patterns:
40+
"$(find)"
41+
replace_with => _value("$(replace)"),
42+
comment => "Search and replace string",
43+
allow_non_convergent => "true";
44+
}
45+
46+
body replace_with _value(x)
47+
{
48+
replace_value => "$(x)";
49+
occurrences => "all";
50+
}
51+
52+
######################################################
53+
54+
bundle agent check
55+
{
56+
vars:
57+
"file_content"
58+
string => readfile( "/tmp/example.txt" , "999" );
59+
60+
classes:
61+
"ok" expression => strcmp("$(file_content)", "foo PORT=22 bar");
62+
63+
files:
64+
"/tmp/example.txt"
65+
delete => tidy;
66+
67+
reports:
68+
ok::
69+
"$(this.promise_filename) Pass";
70+
!ok::
71+
"$(this.promise_filename) FAIL";
72+
}
73+

0 commit comments

Comments
 (0)