File tree Expand file tree Collapse file tree 1 file changed +69
-0
lines changed
tests/acceptance/10_files/replace_patterns Expand file tree Collapse file tree 1 file changed +69
-0
lines changed Original file line number Diff line number Diff line change 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+ files:
29+ "/tmp/example.txt"
30+ edit_line => _regex_replace( "PORT=[0-9]+", "PORT=22" );
31+ }
32+
33+ bundle edit_line _regex_replace(find,replace)
34+ {
35+ replace_patterns:
36+ "$(find)"
37+ replace_with => _value("$(replace)"),
38+ comment => "Search and replace string",
39+ allow_non_convergent => "true";
40+ }
41+
42+ body replace_with _value(x)
43+ {
44+ replace_value => "$(x)";
45+ occurrences => "all";
46+ }
47+
48+ ######################################################
49+
50+ bundle agent check
51+ {
52+ vars:
53+ "file_content"
54+ string => readfile( "/tmp/example.txt" , "999" );
55+
56+ classes:
57+ "ok" expression => strcmp("$(file_content)", "foo PORT=22 bar");
58+
59+ files:
60+ "/tmp/example.txt"
61+ delete => tidy;
62+
63+ reports:
64+ ok::
65+ "$(this.promise_filename) Pass";
66+ !ok::
67+ "$(this.promise_filename) FAIL";
68+ }
69+
You can’t perform that action at this time.
0 commit comments