#######################################################
# Test that specifying two incompatible ways to get package version is detected
# and reported
#######################################################

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

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

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

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

bundle agent test
{
  packages:
      "bash-1.0-amd64"
      package_policy => "add",
      package_method => mock,
      package_version => "2.0",
      package_architectures => { "amd64" },
      classes => test_set_class("overlapping_version_arch_regex_succ",
				"overlapping_version_arch_regex_fail");

      "bash-1.0-i386"
      package_policy => "add",
      package_method => mock_no_name_regex_but_version_regex,
      classes => test_set_class("no_name_regex_version_succ", "no_name_regex_version_fail");

      "bash-1.0-i386"
      package_policy => "add",
      package_method => mock_no_name_regex_but_arch_regex,
      classes => test_set_class("no_name_regex_arch_succ", "no_name_regex_arch_fail");

      "bash-1.0-sparc"
      package_policy => "add",
      package_method => mock_overlapping_version_regex,
      package_version => "2.0",
      classes => test_set_class("overlapping_version_regex_succ",
				"overlapping_version_regex_fail");
}

body package_method mock_overlapping_version_regex
{
      package_changes => "individual";

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

      package_list_command => "$(G.printf) 'bash-1.0-amd64'";
      package_installed_regex => ".*";
      package_list_name_regex => "^([^-]+)";
      package_list_version_regex => "^[^-]+-([^-]+)";
      package_list_arch_regex => "^[^-]+-[^-]+-(.*)";

      package_add_command => "$(G.true) $(this.name)-$(this.version):$(this.arch)";
      package_update_command => "$(G.true)";
      package_delete_command => "$(G.true)";
      package_verify_command => "$(G.true)";
}

body package_method mock_no_name_regex_but_arch_regex
{
      package_changes => "individual";

      package_arch_regex => ".*";
      # but no package_name_regex!

      package_list_command => "$(G.printf) 'bash-1.0-amd64'";
      package_installed_regex => ".*";
      package_list_name_regex => "^([^-]+)";
      package_list_version_regex => "^[^-]+-([^-]+)";
      package_list_arch_regex => "^[^-]+-[^-]+-(.*)";

      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_name_regex_but_version_regex
{
      package_changes => "individual";

      package_version_regex => ".*";
      # but no package_name_regex!

      package_list_command => "$(G.printf) 'bash-1.0-amd64'";
      package_installed_regex => ".*";
      package_list_name_regex => "^([^-]+)";
      package_list_version_regex => "^[^-]+-([^-]+)";
      package_list_arch_regex => "^[^-]+-[^-]+-(.*)";

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

body package_method mock
{
      package_changes => "individual";

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

      package_list_command => "$(G.printf) 'bash-1.0-amd64'";
      package_installed_regex => ".*";
      package_list_name_regex => "^([^-]+)";
      package_list_version_regex => "^[^-]+-([^-]+)";
      package_list_arch_regex => "^[^-]+-[^-]+-(.*)";

      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_name_regex_version_succ", "no_name_regex_version_fail",
                    "!no_name_regex_arch_succ", "no_name_regex_arch_fail",
                    "!overlapping_version_arch_regex_succ", "overlapping_version_arch_regex_fail",
                    "!overlapping_version_regex_succ", "overlapping_version_regex_fail"};

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


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