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

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

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

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

bundle agent init
{
  files:
      "$(g.repofile).*"
      delete => init_delete;

      "$(G.testfile).*"
      delete => init_delete;

      "$(G.testfile)"
      move_obstructions => "true",
      copy_from => init_copy;
}

body copy_from init_copy
{
      source => "$(G.etc_group)";
      compare => "digest";
}

body delete init_delete
{
      dirlinks => "delete";
      rmdirs   => "true";
}

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

bundle agent test
{
  files:
      "$(G.testfile)"
      repository => "tmp",        # Intentionally wrong
      move_obstructions => "true",
      copy_from => test_copy;
}

body copy_from test_copy
{
      source => "$(G.etc_motd)";
      compare => "digest";
}

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

bundle agent check
{
  classes:
      "test" not => fileexists("$(G.testfile).cfsaved");
      "repo" expression => fileexists("$(g.repofile).cfsaved");
      "ok" and => { "test", "repo" };

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

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

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