#######################################################
#
# Test trying to actually specify versions of packages
#
#######################################################
body common control
{
  inputs => { "../default.sub.cf" };
  bundlesequence => { "G", "g", default("$(this.promise_filename)") };
  version => "1.0";
  cache_system_functions => "false";
}

bundle common g
{
  classes:
    "mpm_declared" not => strcmp(getenv("MOCK_PACKAGE_MANAGER", "65535"), "");

  vars:
    mpm_declared::
      "pm" string => getenv("MOCK_PACKAGE_MANAGER", "65535");

    !mpm_declared::
      "pm" string => "$(G.mock_package_manager)";
}

#######################################################
bundle agent init
{
  commands:
    "$(g.pm) --clear-installed";
    "$(g.pm) --clear-available";
    "$(g.pm) --populate-available imagisoft:1.0i:x666";
    "$(g.pm) --populate-available bluesky:3.1:x666";
    "$(g.pm) --add bluesky:*:*";
}

#######################################################
bundle agent test
{
  meta:
    "test_soft_fail"
      string => "windows",
      meta => { "ENT-10215" };

  vars:
    "name" string => "imagisoft";

  packages:
    "$(name)"
      package_policy => "add",
      package_method => mock,
      package_version => "1.0i",
      classes => test_set_class("pass", "fail");
}

body package_method mock
{
  package_changes => "individual";
  package_list_command => "$(g.pm) --list-installed";
  package_list_name_regex => "^[^:]*";
  package_list_version_regex => ":(?<=:).*(?=:)";
  package_installed_regex => "^[^:]*";
  package_add_command => "$(g.pm) --add ";
  package_update_command => "$(g.pm) --update ";
  package_delete_command => "$(g.pm) --delete ";
  package_verify_command => "$(g.pm) --verify ";
  package_name_convention => "$(name):$(version):$(arch)";
}

body classes test_set_class(ok_class, notok_class)
{
  promise_kept => { "$(ok_class)" };
  promise_repaired => { "$(ok_class)" };
  repair_failed => { "$(notok_class)" };
}

#######################################################
bundle agent check
{
  vars:
    "pkgs" string => execresult("$(g.pm) --list-installed", "noshell");

  classes:
    "has_pkg" expression => regcmp(".*imagisoft:1\.0i:x666.*", "$(pkgs)");
    "ok" expression => "pass.!fail.has_pkg";

  reports:
    DEBUG.pass::
      "pass";

    DEBUG.has_pkg::
      "has_pkg";

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

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

body classes successfully_executed(class)
{
  kept_returncodes => { "0" };
  promise_kept => { "$(class)" };
}

### PROJECT_ID: core
### CATEGORY_ID: 29
