######################################################
#
#  Basic test of custom promise types / promise modules
#
#####################################################
body common control
{
    inputs => { "../default.sub.cf" };
    bundlesequence  => { default("$(this.promise_filename)") };
    version => "1.0";
}

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

bundle agent init
{
  files:
    "$(G.testfile)"
      delete => init_delete;
}

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

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

promise agent example
{
    interpreter => "/bin/bash";
    path => "$(this.promise_dirname)/example_module.sh";
}

body classes example
{
        promise_repaired => { "example_promise_repaired" };
}

bundle agent test
{
  meta:
    "description" -> { "CFE-3443" }
      string => "Test that you can add a promise module and evaluate a custom promise";
    "test_soft_fail" string => "windows",
      meta => { "ENT-10217" };


  vars:
    "test_string"
      string => "hello, modules";

  example:
    cfengine::
      "$(G.testfile)"
        message => "$(test_string)",
        classes => example;

  classes:
      "file_created"
        expression => canonify("$(G.testfile)_created"),
        scope => "namespace";
      "file_updated"
        expression => canonify("$(G.testfile)_content_updated"),
        scope => "namespace";
      "file_update_failed"
        expression => canonify("$(G.testfile)_content_update_failed"),
        scope => "namespace";
}

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

bundle agent check
{
  classes:
      "file_ok"
        expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")),
        if => fileexists("$(G.testfile)");

      "ok" expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired";

  reports:
    DEBUG.file_ok::
      "file_ok";
    DEBUG.file_created::
      "file_created";
    DEBUG.file_updated::
      "file_updated";
    DEBUG.file_update_failed::
      "file_update_failed";
    DEBUG.example_promise_repaired::
      "example_promise_repaired";

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