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

bundle agent init
{
  commands:
    "$(G.make) install DESTDIR=$(G.testdir)"
      contain => in_dir_shell("$(this.promise_dirname)/../../..");

  vars:
    # If masterfiles are installed with --prefix=/other/prefix then we
    # need to figure out where did "make install DESTDIR=..." has put
    # the files.
    "promises_cf_slist" slist => findfiles("$(G.testdir)/**/promises.cf");
    "promises_cf_path" string => nth(promises_cf_slist, 0);
    "masterfiles_path" string => dirname("$(promises_cf_path)");
    "def_cf_path" string => concat("$(masterfiles_path)", "/controls/def.cf");
}

bundle agent test
{
  meta:
    "description"
      string => "Test that enabling autorun from policy is not sufficient for activation.

In order to prevent the parsing of files unnecessarily we guard that with the
definition of the services_autorun class. If that class is defined from
policy, as in this test it currently happens too late in order to pick up
the policy in the services/autorun directory. It would be OK for this
behavior to change so that defining from policy worked as desired. This
test is intended to track that specific case and if ever fixed, simply
update this test to allow it to pass.";

    "test_soft_fail"
      string => "any",
      meta => { "redmine7572", "jiraCFE2135" };

  files:
    "$(init.def_cf_path)" edit_line => enable_autorun;
}

bundle edit_line enable_autorun
{
  insert_lines:
    'bundle common __autorun_enable { classes: "services_autorun" expression => "any"; }';
}
#######################################################
bundle agent check
{
  methods:
    ""
      usebundle => dcs_passif_output(
        ".*R: hello_world_autorun: Hello, this is an automatically loaded bundle.*",
        "",
        "$(sys.cf_agent) -v -f $(init.promises_cf_path) | $(G.grep) Hello",
        $(this.promise_filename)
      );
}
