#######################################################
#
# Test that getindices on an array variable will resolve to 2 levels
#
#######################################################
body common control
{
  inputs => { "../../default.sub.cf" };
  bundlesequence => { default("$(this.promise_filename)") };
  version => "1.0";
}

#######################################################
# Do not change the name of this bundle or of variables inside this bundle. The
# original bug CFE-2397 depended on a certain order in the variable table which
# was triggered by these names.
bundle common b
{
  vars:
    "d[k]" string => "val1";
    "d[f][f1]" string => "val2";
    "d[s][s1]" string => "val3";
    "d_keys" slist => getindices("d");
    "d_keys_f" slist => getindices("d[f]");
    "d_keys_s" slist => getindices("d[s]");
    "c[$(d_keys)]" string => "$(d[$(d_keys)])";
    "c[f][$(d_keys_f)]" string => "$(d[f][$(d_keys_f)])";
    "c[s][$(d_keys_s)]" string => "$(d[s][$(d_keys_s)])";
    "c_keys" slist => getindices("c");
    "c_keys_f" slist => getindices("c[f]");
    "c_keys_s" slist => getindices("c[s]");
}

bundle agent test
{
  vars:
    "user[name]" string => "zamboni";
    "user[fullname][first]" string => "Diego";
    "user[fullname][last]" string => "Zamboni";

    "user[dirs]"
      slist => { "/home/zamboni", "/tmp/zamboni", "/export/home/zamboni" };

    "fields" slist => getindices("user");
    "userfields" slist => getindices("user[fullname]");
    "inline_fields" slist => getindices('{ "foo": 1, "bar": 2 }');
    "inline_numfields" slist => getindices('[ "foo", 1, "bar", 2 ]');
    "inline_function" slist => getindices(parsejson('{ "a": "b", "c": "d" }'));
    "c_keys" slist => { @(b.c_keys) };
    "c_keys_f" slist => { @(b.c_keys_f) };
    "c_keys_s" slist => { @(b.c_keys_s) };
}

#######################################################
bundle agent check
{
  methods:
    "check"
      usebundle => dcs_check_state(
        test,
        "$(this.promise_filename).expected.json",
        $(this.promise_filename)
      );
}
