######################################################
#
#  Test that custom promises can use unless attribute
#
#####################################################
body common control
{
    inputs => { "../default.cf.sub" };
    bundlesequence  => { default("$(this.promise_filename)") };
    version => "1.0";
}

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

bundle agent init
{
  files:
    "$(G.testfile)-0"
      delete => init_delete;
    "$(G.testfile)-1"
      delete => init_delete;
    "$(G.testfile)-2"
      delete => init_delete;
    "$(G.testfile)-3"
      delete => init_delete;
    "$(G.testfile)-4"
      delete => init_delete;
    "$(G.testfile)-5"
      delete => init_delete;
    "$(G.testfile)-6"
      delete => init_delete;
    "$(G.testfile)-7"
      delete => init_delete;
    "$(G.testfile)-8"
      delete => init_delete;
    "$(G.testfile)-9"
      delete => init_delete;
    "$(G.testfile)-10"
      delete => init_delete;
}

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

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

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

bundle agent test
{
  meta:
    "description" -> { "CFE-3431" }
      string => "Test that custom promises work with unless attribute";
    "test_soft_fail" string => "windows",
      meta => { "ENT-10217" };

  vars:
    "false_variable"
      string => "cfengine.(!cfengine)";
    "true_variable"
      string => "cfengine|(!cfengine)";

  example:
    cfengine::
      "$(G.testfile)-0" # Created - no condition
        message => "x";
      "$(G.testfile)-1" # Not created - true condition
        message => "x",
        unless => "cfengine";
      "$(G.testfile)-2" # Not created - true condition from variable
        message => "x",
        unless => "$(true_variable)";
      "$(G.testfile)-3" # Not created - true condition (inverted false variable)
        message => "x",
        unless => "!($(false_variable))";
      "$(G.testfile)-4" # NOT - not function call of something false
        message => "x",
        unless => not("$(false_variable)");
      "$(G.testfile)-5" # Created - false condition
        message => "x",
        unless => "!cfengine";
      "$(G.testfile)-6" # Created - false condition from variable
        message => "x",
        unless => "$(false_variable)";
      "$(G.testfile)-7" # Created - false condition (inverted true variable)
        message => "x",
        unless => "!($(true_variable))";
      "$(G.testfile)-8" # Created - not function call of something true
        message => "x",
        unless => not("$(true_variable)");
      "$(G.testfile)-9" # Created - undefined variable in unless
        message => "x",
        unless => "$(undefined_variable)";
      "$(G.testfile)-10" # Created - unresolved function call in unless
        message => "x",
        unless => not("$(undefined_variable)");
}

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

bundle agent check
{
  classes:
    "ok"
      and => {
        fileexists("$(G.testfile)-0"),
        not(fileexists("$(G.testfile)-1")),
        not(fileexists("$(G.testfile)-2")),
        not(fileexists("$(G.testfile)-3")),
        not(fileexists("$(G.testfile)-4")),
        fileexists("$(G.testfile)-5"),
        fileexists("$(G.testfile)-6"),
        fileexists("$(G.testfile)-7"),
        fileexists("$(G.testfile)-8"),
        fileexists("$(G.testfile)-9"),
        fileexists("$(G.testfile)-10"),
      };

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