#######################################################
#
# 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_json_path" string => concat("$(masterfiles_path)", "/def.json");
}

bundle agent test
{
  meta:
    "description"
      string => "Test that def.json can enable autorun as expected.";
  # We need to lay down the def.json that will enable autorun.
  files:
    "$(init.def_json_path)"
      create => "true",
      edit_line => enable_autorun;
}

bundle edit_line enable_autorun
{
  insert_lines:
    '{ "classes": { "services_autorun": ["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)
      );
}
