#######################################################
#
# Test cf-serverd related promises, mtime simple copy localhost
# The source server has access_rules admit=>{"localhost"}
#
#######################################################

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

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

bundle agent init
{
}

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

bundle agent test
{
  files:
    # localhost_open_hostname
      "$(G.testdir)/server1_classic" copy_from => copy_file("9884", "classic");
      "$(G.testdir)/server1_latest"  copy_from => copy_file("9884", "latest");
    # localhost_open_admit_hostnames
      "$(G.testdir)/server2_classic" copy_from => copy_file("9886", "classic");
      "$(G.testdir)/server2_latest"  copy_from => copy_file("9886", "latest");
}

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

body copy_from copy_file(port, protocol_version)
{
      source      => "$(G.testdir)/source_file";
      servers     => { "127.0.0.1" };
      compare     => "mtime";
      copy_backup => "false";

      portnumber       => "$(port)";
      protocol_version => "$(protocol_version)";

      #encrypt     => "true";
      #verify      => "true";
      #purge       => "false";
      #type_check  => "true";
      #force_ipv4  => "true";
      trustkey => "true";
}

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

bundle agent check
{
  classes:
      "dummy" expression => regextract("(.*)\.sub", $(this.promise_filename), "fn");

  methods:
      "any" usebundle => dcs_if_diff_expected(
                             "$(G.testdir)/source_file", "$(G.testdir)/server1_classic",
                             "no", "same_classic1", "differ_classic1");
      "any" usebundle => dcs_if_diff_expected(
                             "$(G.testdir)/source_file", "$(G.testdir)/server1_latest",
                             "no", "same_latest1", "differ_latest1");
      "any" usebundle => dcs_if_diff_expected(
                             "$(G.testdir)/source_file", "$(G.testdir)/server2_classic",
                             "no", "same_classic2", "differ_classic2");
      "any" usebundle => dcs_if_diff_expected(
                             "$(G.testdir)/source_file", "$(G.testdir)/server2_latest",
                             "no", "same_latest2", "differ_latest2");

  reports:

    same_classic1.same_latest1.same_classic2.same_latest2::
      "$(fn[1]) Pass";
    !same_classic1|!same_latest1|!same_classic2|!same_latest2::
      "$(fn[1]) FAIL";

}
