File: common.cf.sub

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (96 lines) | stat: -rw-r--r-- 2,659 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
bundle common inform_tests
{
  vars:
    "inputs" slist => { "$(this.promise_dirname)/../default.cf.sub" };
}

body common control
{
  inputs => { "@(inform_tests.inputs)" };
  version => "1.0";

  # RUNDIRECT is used later to only run the actual test code with cf-agent
  !RUNDIRECT::
      bundlesequence  => { default("$(this.promise_filename)") };
}

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

bundle agent init
{
  classes:
    "expected_file_exists" expression => fileexists("$(testcase.filename).expected"),
      scope => "namespace";
    "has_setup" expression => isgreaterthan(length(bundlesmatching("default:setup")), "0"),
      scope => "namespace";
    "has_teardown" expression => isgreaterthan(length(bundlesmatching("default:teardown")), "0"),
      scope => "namespace";

  files:
    "$(G.testfile)"
      delete => init_delete,
      handle => "file_deleted";
    "$(G.testdir)"
      delete => init_delete,
      handle => "dir_deleted";

  methods:
    has_setup::
      "setup"
        depends_on => { "dir_deleted", "file_deleted" };
}

body delete init_delete
{
      dirlinks => "delete";
      rmdirs   => "true";
}

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

bundle agent test
{
  meta:
    "test_soft_fail" string => "windows",
      meta => { "ENT-10406" },
      if => not( strcmp( "insert_lines_noop.cf", "$(sys.policy_entry_basename)" ) );
  vars:
    "cf_agent" string => ifelse(isvariable("sys.cf_agent"), "$(sys.cf_agent)", "/var/cfengine/bin/cf-agent");
    "filter_list" slist => { " -e '/filestat bailing/d' ",
                        " -e s,$(G.testroot),/tmp,g ",
                        " -e s,/usr/local/bin/gzip,/bin/gzip, "};
    "filters" string => join("", filter_list);
  commands:
    # NOTE: easy debug, if you change `>` to `|tee` in all below then you can see results in the execution log
    "$(cf_agent) -D RUNDIRECT -KIf $(testcase.filename) > $(testcase.filename).log"
      contain => useshell;
    "$(G.sed) $(filters) $(testcase.filename).log > $(testcase.filename).actual"
      contain => useshell;
}

body contain useshell
{
  useshell => "useshell";
}

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

bundle agent check
{
  methods:
    has_teardown::
      "teardown"; # optional tear down step contained in the test.cf file
    expected_file_exists::
      "any" usebundle => dcs_if_diff("$(testcase.filename).actual", "$(testcase.filename).expected", "ok", "not_ok");

  files:
    ok::
      "$(testcase.filename).(log|actual)"
        delete => tidy;

  reports:
    ok::
      "$(testcase.filename) Pass";
    !ok::
      "$(testcase.filename) FAIL";
}