# Test that variables can be passed across bundles and namespaces
body common control
{
  inputs => { "../../default.sub.cf" };
  bundlesequence => { default("$(this.promise_filename)") };
  version => "1.0";
}

bundle agent init
{
}

bundle agent test
{
  vars:
    "x" string => "datax";
    "y" slist => { "datay1", "datay2" };
    "z" data => parsejson('{ "hello": "there" }');

  meta:
    "test_skip_needs_work" string => "windows";

  methods:
    "x" usebundle => see_scalar($(x));
    "y" usebundle => see_slist(@(test.y));
    "z" usebundle => see_data(@(z));
}

bundle agent see_scalar(svar)
{
  classes:
    "saw_scalar"
      scope => "namespace",
      expression => strcmp($(svar), "datax");

  reports:
    DEBUG::
      "The passed-in string was $(svar)";
}

bundle agent see_slist(lvar)
{
  vars:
    "concat" string => join(",", lvar);

  classes:
    "saw_slist"
      scope => "namespace",
      expression => strcmp($(concat), "datay1,datay2");

  reports:
    DEBUG::
      "The passed-in slist was $(lvar)";
}

bundle agent see_data(cvar_passed)
{
  vars:
    "concat_passed" string => storejson(cvar_passed);
    "cvar_local" data => parsejson('{ "hello": "there" }');
    "concat_local" string => storejson(cvar_local);

    # generates a warning about "can't find container named cvar_passed"
    "dummy" data => mergedata(cvar_local, cvar_passed);

  classes:
    "saw_data"
      scope => "namespace",
      expression => strcmp($(concat_passed), '{
  "hello": "there"
}');

  reports:
    DEBUG::
      "The passed-in container as string was $(concat_passed)";
      "The local container as string was $(concat_local)";
}

bundle agent check
{
  classes:
    "ok" and => { "saw_scalar", "saw_slist", "saw_data" };

  reports:
    DEBUG.!saw_scalar::
      "The scalar passing didn't work";

    DEBUG.!saw_slist::
      "The slist passing didn't work";

    DEBUG.!saw_data::
      "The data passing didn't work";

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

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