1body common control
2{
3        inputs => { "../../default.cf.sub" };
4        bundlesequence  => { default("$(this.promise_filename)") };
5        version => "1.0";
6}
7
8bundle agent init
9{
10  vars:
11
12      "template" string => "# Test1
13{{#testcase.test1}}
14{{#data}}
15Data = {{.}}
16{{/data}}
17{{/testcase.test1}}
18
19# Test2
20{{#testcase.test2.data}}
21Data = {{.}}
22{{/testcase.test2.data}}
23{{#testcase.test2.otherdata}}
24Other data = {{.}}
25{{/testcase.test2.otherdata}}";
26
27      "data" data => '{
28  "testcase": {
29    "test1": {
30      "data": [
31        "v1",
32        "v2"
33      ]
34    },
35    "test2": {
36      "data": [
37        "v1",
38        "v2"
39      ],
40      "otherdata": [
41        "v3",
42        "v4"
43      ]
44    }
45  }
46      }';
47
48}
49
50bundle agent test
51{
52  meta:
53
54      # The issue we see in cfengine is that if a {{#testcase.test2}} section is
55      # used the corresponding JSON object is iterated over and the rendering
56      # happens for each sub structure (property) iterated duplicating the
57      # data. The workaround is to not use a separate section corresponding to
58      # the testcase.test2 JSON object with multiple properties.
59
60      "description" -> { "CFE-2125" }
61        string => "Test a workaround for iterating over object to get a single
62                   block with correct context (CFE-2125).";
63
64  vars:
65      "got" string => string_mustache( $(init.template), @(init.data) );
66}
67
68bundle agent check
69{
70  reports:
71    DEBUG::
72      "got output: $(test.got)";
73
74  vars:
75      "expected" string => "# Test1
76Data = v1
77Data = v2
78
79# Test2
80Data = v1
81Data = v2
82Other data = v3
83Other data = v4
84";
85
86  methods:
87      "check" usebundle => dcs_check_strcmp( $(test.got), $(check.expected), $(this.promise_filename), "no" );
88}
89