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

#######################################################
bundle agent init
{
  files:
    "$(G.testfile)-1.expected"
      copy_from => local_cp("$(this.promise_filename).finish");

    "$(G.testfile)-1.actual"
      copy_from => local_cp("$(this.promise_filename).start");

    "$(G.testfile)-2.expected"
      copy_from => local_cp("$(this.promise_filename).finish");

    "$(G.testfile)-2.actual"
      copy_from => local_cp("$(this.promise_filename).start");
}

#######################################################
bundle agent test
{
  vars:
    "config[use chroot]" string => "maybe";

    # should uncomment the existing line
    "config[pid file]" string => "/tmp/rsyncd.pid";

    # should insert a new line at the end, this is missing
    "config[fake setting]" string => "anything";

    # should uncomment the line and edit the value
    "config[read only]" string => ".* maybe";

    # blanks should be OK
    "config[blank option]" string => "";

  files:
    "$(G.testfile)-1.actual" edit_line => set_variable_values("test.config");
    "$(G.testfile)-2.actual" edit_line => set_variable_values("test.config");
}

#######################################################
bundle agent check
{
  vars:
    "files" slist => { "1", "2" };

  classes:
    "pass" and => { "1_pass", "2_pass" };

  methods:
    "sort actual"
      usebundle => dcs_sort(
        "$(G.testfile)-$(files).actual", "$(G.testfile)-$(files).actual.sort"
      );

    "sort expected"
      usebundle => dcs_sort(
        "$(G.testfile)-$(files).expected",
        "$(G.testfile)-$(files).expected.sort"
      );

    "check"
      usebundle => dcs_if_diff(
        "$(G.testfile)-$(files).actual.sort",
        "$(G.testfile)-$(files).expected.sort",
        "$(files)_pass",
        "$(files)_fail"
      );

    # Fail the test if any of the files fail.
    "fail"
      usebundle => dcs_fail($(this.promise_filename)),
      if => "$(files)_fail";

    pass::
      "pass" usebundle => dcs_pass($(this.promise_filename));

  reports:
    DEBUG::
      "$(files)_fail" if => "$(files)_fail";
}
