1#######################################################
2#
3# Test maparray()
4#
5#######################################################
6
7body common control
8{
9      inputs => { "../../default.cf.sub" };
10      bundlesequence  => { default("$(this.promise_filename)") };
11      version => "1.0";
12}
13
14#######################################################
15
16bundle agent init
17{
18}
19
20#######################################################
21
22bundle agent test
23{
24  vars:
25      "load1" data => parsejson('[ 1, 2, 3]');
26      "load2" slist => { "eleme\"nt1", "element2", "element3" };
27      "load3" data => parsejson('{ "x\\"x": "y\\"y" }');
28      "load4" data => parsejson('[]');
29      "load5[mykey]" slist => { "myvalue" };
30      "load5[anotherkey]" string => "anothervalue";
31      "load5[lastkey!]" slist => { "o\"ne", "two", "three" };
32      "load6" data => parsejson('{ "a": { "b": "c" } }');
33
34      "static[x]" string => "xvalue";
35      "static[x\"x]" string => "xxvalue";
36      "static[0]" string => "0value";
37      "static[1]" string => "1value";
38      "static[2]" string => "2value";
39      "static[lastkey!]" string => "lastvalue";
40      "static[anotherkey]" string => "anothervalue";
41      "static[mykey]" string => "myvalue";
42      "static[a]" string => "avalue";
43
44      "spec1" string => "key = $(this.k)";
45      "spec2" string => "key = $(this.k), value = ${this.v}";
46      "spec3" string => "key = $(this.k), key2 = $(this.k[1]), value = ${this.v}";
47      "spec4" string => "xvalue should be $(static[$(this.k)])";
48
49      "jsonspec1" string => '{ "key": "$(this.k)", "value": "$(this.v)"';
50      "jsonspec2" string => '{ "key": "$(this.k)", "value": "$(this.v)" }';
51      "jsonspec3" string => '[ "$(this.k)", "$(this.v)" ]';
52      "jsonspec4" string => '{ "key": "$(this.k)", "key2": "$(this.k[1])", "value": "$(this.v)" }';
53
54      "X" slist => { "1", "2", "3", "4", "5", "6" };
55      "Y" slist => { "1", "2", "3", "4" };
56
57      "maparray_$(X)_$(Y)" slist => sort(maparray("$(spec$(Y))", "load$(X)"));
58      "bad2" slist => maparray("", missingvar);
59
60      "justastring" string => "me";
61      "bad4" slist => maparray("", justastring);
62}
63
64#######################################################
65
66bundle agent check
67{
68  methods:
69      "check"  usebundle => dcs_check_state(test,
70                                           "$(this.promise_filename).expected.json",
71                                           $(this.promise_filename));
72}
73