##############################################################################
#
# Test that agent can override the immutable bit when using touch attribute
#
##############################################################################

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

bundle agent global
{
  vars:
    "testfile"
      string => "/tmp/08_immutable.txt";
}

body fsattrs set_immutable
{
  immutable => "true";
}

bundle agent init
{
  commands:
    "touch -d @0 $(global.testfile)"
      contain => in_shell;
    "chattr +i $(global.testfile)"
      contain => in_shell;
}

bundle agent test
{
  meta:
    "description" -> { "CFE-1840", "ENT-10961" }
      string => "Test that agent can override the immutable bit on a file while using the touch attribute";

    "test_skip_unsupported"
      string => "hpux|aix|solaris|windows";

  files:
    "$(global.testfile)"
      fsattrs => set_immutable,
      touch => "true";
}

bundle agent check
{
  vars:
    "not_expected"
      string => "0";
    "actual"
      string => filestat("$(global.testfile)", "mtime");

  classes:
    "ok"
      expression => not(strcmp("$(actual)", "$(not_expected)"));

  reports:
    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
    any::
      "Not expecting $(not_expected), got $(actual)";
}

bundle agent destroy
{
  commands:
    "chattr -i $(global.testfile)"
      contain => in_shell,
      handle => "is mutable";

  files:
    "$(global.testfile)"
      delete => tidy,
      depends_on => { "is mutable" };
}
