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

bundle agent test
{
  meta:
    "description" -> { "ENT-9962" }
      string => "Test variable arguments with getusers()";

    "test_skip_unsupported" string => "windows";

  vars:
    "user_entries"
      slist => splitstring(string_trim(readfile("/etc/passwd")), "\n", 999);

    "name_list"
      slist => maplist(
        nth(splitstring("$(this)", ":", 1), 0), "@(user_entries)"
      );

    "actual_users_content" string => join(" ", sort("@(name_list)", "lex"));
    "users1" slist => getusers();
    "users2" slist => getusers("");
    "users3" slist => getusers("", "");
    "retrieved_users_content_1" string => join(" ", sort("@(users1)", "lex"));
    "retrieved_users_content_2" string => join(" ", sort("@(users2)", "lex"));
    "retrieved_users_content_3" string => join(" ", sort("@(users3)", "lex"));
}

bundle agent check
{
  classes:
    "ok"
      expression => and(
        strcmp(
          "$(test.actual_users_content)", "$(test.retrieved_users_content_1)"
        ),
        strcmp(
          "$(test.actual_users_content)", "$(test.retrieved_users_content_2)"
        ),
        strcmp(
          "$(test.actual_users_content)", "$(test.retrieved_users_content_3)"
        )
      );

  reports:
    ok::
      "$(this.promise_filename) Pass";

    !ok::
      "$(this.promise_filename) FAIL";
}
