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

#######################################################
bundle agent init
{
  vars:
    "expectations" string => ifelse("cfengine_3_10", "3.10.x", "");

  files:
    # The tested file "actual" is copied from our seeded starting position.
    "$(G.testfile).actual"
      copy_from => local_cp("$(this.promise_filename).start");

    # Next we place the file which we will compare the final result with.
    "$(G.testfile).expected"
      copy_from => local_cp("$(this.promise_filename).finish$(expectations)");
}

#######################################################
bundle agent test
{
  meta:
    "description" -> { "CFE-3221", "CFE-3244" }
      string => "Test expected behavior of manage_variable_values_ini";

  vars:
    "config[section][keyone]" string => "1";
    "config[section][keytwo]" string => "valuetwo";
    "config[CFE-3221][variablename]" string => "desired value";
    "config[CFE-3221][variablename2]" string => "desired value2";
    "config[CFE-3221][variablename3]" string => "desired value3";
    "config[CFE-3221][variablename4]" string => "desired value4";
    "config[CFE-3221][variablename5]" string => "desired value5";
    "config[CFE-3221][variablename6]" string => "desired value6";
    "config[CFE-3221][variablename7]" string => "desired value7";
    "config[CFE-3221][variablename8]" string => "desired value8";
    "config[CFE-3244][keyone]" string => "1";
    "config[CFE-3244][keytwo]" string => "valuetwo";

  files:
    "$(G.testfile).actual"
      edit_line => manage_variable_values_ini("test.config", "section");

    "$(G.testfile).actual" -> { "CFE-3221" }
      edit_line => manage_variable_values_ini("test.config", "CFE-3221");

    "$(G.testfile).actual" -> { "CFE-3244" }
      edit_line => manage_variable_values_ini("test.config", "CFE-3244");
}

#######################################################
bundle agent check
{
  methods:
    "check"
      usebundle => dcs_if_diff(
        "$(G.testfile).actual", "$(G.testfile).expected", "pass", "_fail"
      );

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

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