#######################################################
# Test for presence of "main" attribute, given the presence of "dependent"
# attributes, which do not make sense without the "main" attribute.
#
# main attribute: package_list_command
# dependent attributes: 
#     package_installed_regex
#     package_list_arch_regex
#     package_list_name_regex
#     package_list_version_regex
#     package_multiline_start
#######################################################

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

bundle agent init
{
  vars:
      "dummy" string => "dummy";
}

bundle agent test
{
  meta:
      # Windows has its own mechanism to list packages, and doesn't use the package body.
      "test_skip_unsupported" string => "windows";

  packages:
      "bash-1.0-amd64"
      package_policy => "add",
      package_method => mock_no_list_command_package_installed_regex,
      classes => test_set_class("no_list_command_package_installed_regex_succ",
				"no_list_command_package_installed_regex_fail");

      "bash-2.0-amd64"
      package_policy => "add",
      package_method => mock_no_list_command_package_arch_regex,
      classes => test_set_class("no_list_command_package_arch_regex_succ",
				"no_list_command_package_arch_regex_fail");

      "bash-1.0-i386"
      package_policy => "add",
      package_method => mock_no_list_command_package_name_regex,
      classes => test_set_class("no_list_command_package_name_regex_succ",
				"no_list_command_package_name_regex_fail");

      "bash-1.0-sparc"
      package_policy => "add",
      package_method => mock_no_list_command_package_version_regex,
      classes => test_set_class("no_list_command_package_version_regex_succ",
				"no_list_command_package_version_regex_fail");
}

body package_method mock_no_list_command_package_version_regex
{
      package_changes => "individual";

      package_name_regex => "^([^-]+)";
      package_version_regex => "^[^-]+-([^-]+)";
      package_arch_regex => "^[^-]+-[^-]+-(.*)";

      package_file_repositories => { "/package/repos1", "package/repos2" };
      # but no package_list_command!
      #  package_installed_regex => ".*";
      #  package_list_arch_regex => "^[^-]+-[^-]+-(.*)";
      #  package_list_name_regex => "^([^-]+)";
      package_list_version_regex => "^[^-]+-([^-]+)";
      #  package_multiline_start => 


      package_add_command => "$(G.false)";
      package_update_command => "$(G.false)";
      package_delete_command => "$(G.false)";
      package_verify_command => "$(G.false)";
}

body package_method mock_no_list_command_package_name_regex
{
      package_changes => "individual";


      package_name_regex => "^([^-]+)";
      package_version_regex => "^[^-]+-([^-]+)";
      package_arch_regex => "^[^-]+-[^-]+-(.*)";

      package_file_repositories => { "/package/repos1", "package/repos2" };
      # but no package_list_command!
      #  package_installed_regex => ".*";
      #  package_list_arch_regex => "^[^-]+-[^-]+-(.*)";
      package_list_name_regex => "^([^-]+)";
      #  package_list_version_regex => "^[^-]+-([^-]+)";
      #  package_multiline_start => 


      package_add_command => "$(G.false)";
      package_update_command => "$(G.false)";
      package_delete_command => "$(G.false)";
      package_verify_command => "$(G.false)";
}

body package_method mock_no_list_command_package_arch_regex
{
      package_changes => "individual";


      package_name_regex => "^([^-]+)";
      package_version_regex => "^[^-]+-([^-]+)";
      package_arch_regex => "^[^-]+-[^-]+-(.*)";

      package_file_repositories => { "/package/repos1", "package/repos2" };
      # but no package_list_command!
      #  package_installed_regex => ".*";
      package_list_arch_regex => "^[^-]+-[^-]+-(.*)";
      #  package_list_name_regex => "^([^-]+)";
      #  package_list_version_regex => "^[^-]+-([^-]+)";
      #  package_multiline_start => 


      package_add_command => "$(G.false)";
      package_update_command => "$(G.false)";
      package_delete_command => "$(G.false)";
      package_verify_command => "$(G.false)";
}

body package_method mock_no_list_command_package_installed_regex
{
      package_changes => "individual";


      package_name_regex => "^([^-]+)";
      package_version_regex => "^[^-]+-([^-]+)";
      package_arch_regex => "^[^-]+-[^-]+-(.*)";

      package_file_repositories => { "/package/repos1", "package/repos2" };
      # but no package_list_command!
      package_installed_regex => ".*";
      #  package_list_arch_regex => "^[^-]+-[^-]+-(.*)";
      #  package_list_name_regex => "^([^-]+)";
      #  package_list_version_regex => "^[^-]+-([^-]+)";
      #  package_multiline_start => 


      package_add_command => "$(G.false)";
      package_update_command => "$(G.false)";
      package_delete_command => "$(G.false)";
      package_verify_command => "$(G.false)";
}

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

#######################################################

bundle agent check
{
  classes:
      "ok" and => { "!no_list_command_package_installed_regex_succ", "no_list_command_package_installed_regex_fail",
                    "!no_list_command_package_arch_regex_succ", "no_list_command_package_arch_regex_fail",
                    "!no_list_command_package_name_regex_succ", "no_list_command_package_name_regex_fail",
                    "!no_list_command_package_version_regex_succ", "no_list_command_package_version_regex_fail",
      };

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

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