#######################################################
#
# Try to delete a line, action_policy=>"warn", ensure that a repair_denied class gets set (issue 441)
#
#######################################################

body common control
{
      inputs => { "../../default.sub.cf" };
      bundlesequence  => { default("$(this.promise_filename)") };   
      version => "1.0";
}

bundle common g
{
  vars:
      "testfile" string => "/tmp/TEST.cfengine";
}

#######################################################

bundle agent init
{
  vars:
      "states" slist => { "actual", "expected" };

      "actual" string =>
      "keep this
and this
but delete one line
keep this too";
      
      "expected" string =>
      "keep this
and this
but delete one line
keep this too";
      
  files:
      "$(G.testfile).$(states)"
      create => "true",
      edit_line => init_insert("$(init.$(states))"),
      edit_defaults => init_empty;
}

bundle edit_line init_insert(str)
{
  insert_lines:
      "$(str)";
}

body edit_defaults init_empty
{
      empty_file_before_editing => "true";
}

#######################################################

bundle agent test
{
  vars:
      "tstr" string => ".*delete.*";
      
  files:
      "$(G.testfile).actual"
      edit_line => test_delete("$(test.tstr)");

}

bundle edit_line test_delete(str)
{
  delete_lines:
      "$(str)"
      classes => full_set;
}

body classes full_set
{
      promise_kept     => { "fail" };
      promise_repaired => { "fail" };
      repair_failed    => { "fail" };
      repair_denied    => { "pass" };
      repair_timeout   => { "fail" };
}


#######################################################

bundle agent check
{
  classes:
      "no_difference" expression => returnszero(
						 "$(G.diff) -q $(G.testfile).actual $(G.testfile).expected",
						 "noshell");
      "ok" and => { "pass", "!fail", "no_difference" };

  reports:
    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
}

#######################################################

bundle agent fini
{
  methods:
      "any" usebundle => dcs_fini("$(G.testfile).*");
}
### PROJECT_ID: core
### CATEGORY_ID: 27
