Skip to content

Commit 51816e8

Browse files
committed
Added acceptance tests for classfilterdata
Ticket: ENT-10961, CFE-1840 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
1 parent b4bbcc1 commit 51816e8

File tree

4 files changed

+316
-0
lines changed

4 files changed

+316
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
body common control
2+
{
3+
bundlesequence => { "check" };
4+
}
5+
6+
bundle agent test(context, index)
7+
{
8+
meta:
9+
"description" -> { "ENT-6193", "CFE-3421" }
10+
string => "Test for expected results from policy function classfilterdata() with array of arrays using context '$(with)' and index $(index)",
11+
with => join("', '", "context");
12+
13+
vars:
14+
"test"
15+
data => '[
16+
[ "foo", "!foo", "foo&bar", "foo|bar" ],
17+
[ "bar", "!bar", "bar&baz", "bar|baz" ],
18+
[ "baz", "!baz", "foo&baz", "foo|baz" ],
19+
]';
20+
21+
"actual"
22+
data => classfilterdata("@(test)", "array_of_arrays", "$(index)");
23+
24+
classes:
25+
"$(context)";
26+
27+
reports:
28+
"$(with)"
29+
with => storejson("@(actual)"),
30+
bundle_return_value_index => "$(index)";
31+
}
32+
33+
bundle agent check
34+
{
35+
vars:
36+
"num_indices" string => "3";
37+
"context" slist => { "foo" };
38+
"range" slist => expandrange("[0-$(num_indices)]", "1");
39+
40+
"expected[0]"
41+
string => storejson('[
42+
[ "foo", "!foo", "foo&bar", "foo|bar" ],
43+
]');
44+
"expected[1]"
45+
string => storejson('[
46+
[ "bar", "!bar", "bar&baz", "bar|baz" ],
47+
[ "baz", "!baz", "foo&baz", "foo|baz" ],
48+
]');
49+
"expected[2]"
50+
string => storejson('[
51+
]');
52+
"expected[3]"
53+
string => storejson('[
54+
[ "foo", "!foo", "foo&bar", "foo|bar" ],
55+
[ "baz", "!baz", "foo&baz", "foo|baz" ],
56+
]');
57+
58+
classes:
59+
"ok_$(range)"
60+
expression => strcmp("$(expected[$(range)])",
61+
"$(actual[$(range)])");
62+
"ok"
63+
expression => and(expandrange("ok_[0-$(num_indices)]", "1"));
64+
65+
methods:
66+
"context: '$(with)' and index: $(range)"
67+
usebundle => test("@(context)", "$(range)"),
68+
useresult => "actual",
69+
with => join(", ", "context");
70+
71+
reports:
72+
"Context '$(with)'; index $(range); expected '$(expected[$(range)])'; actual '$(actual[$(range)])'"
73+
with => join("', '", "context");
74+
ok::
75+
"$(this.promise_filename) Pass";
76+
!ok::
77+
"$(this.promise_filename) FAIL";
78+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
body common control
2+
{
3+
bundlesequence => { "check" };
4+
}
5+
6+
bundle agent test(context, index)
7+
{
8+
meta:
9+
"description" -> { "ENT-6193", "CFE-3421" }
10+
string => "Test for expected results from policy function classfilterdata() with array of arrays using context '$(with)' and index $(index)",
11+
with => join("', '", "context");
12+
13+
vars:
14+
"test"
15+
data => '[
16+
[ "foo", "!foo", "foo&bar", "foo|bar" ],
17+
[ "bar", "!bar", "bar&baz", "bar|baz" ],
18+
[ "baz", "!baz", "foo&baz", "foo|baz" ],
19+
]';
20+
21+
"actual"
22+
data => classfilterdata("@(test)", "array_of_arrays", "$(index)");
23+
24+
classes:
25+
"$(context)";
26+
27+
reports:
28+
"$(with)"
29+
with => storejson("@(actual)"),
30+
bundle_return_value_index => "$(index)";
31+
}
32+
33+
bundle agent check
34+
{
35+
vars:
36+
"num_indices" string => "3";
37+
"context" slist => { "foo", "bar" };
38+
"range" slist => expandrange("[0-$(num_indices)]", "1");
39+
40+
"expected[0]"
41+
string => storejson('[
42+
[ "foo", "!foo", "foo&bar", "foo|bar" ],
43+
[ "bar", "!bar", "bar&baz", "bar|baz" ],
44+
]');
45+
"expected[1]"
46+
string => storejson('[
47+
[ "baz", "!baz", "foo&baz", "foo|baz" ],
48+
]');
49+
"expected[2]"
50+
string => storejson('[
51+
[ "foo", "!foo", "foo&bar", "foo|bar" ],
52+
]');
53+
"expected[3]"
54+
string => storejson('[
55+
[ "foo", "!foo", "foo&bar", "foo|bar" ],
56+
[ "bar", "!bar", "bar&baz", "bar|baz" ],
57+
[ "baz", "!baz", "foo&baz", "foo|baz" ],
58+
]');
59+
60+
classes:
61+
"ok_$(range)"
62+
expression => strcmp("$(expected[$(range)])",
63+
"$(actual[$(range)])");
64+
"ok"
65+
expression => and(expandrange("ok_[0-$(num_indices)]", "1"));
66+
67+
methods:
68+
"context: '$(with)' and index: $(range)"
69+
usebundle => test("@(context)", "$(range)"),
70+
useresult => "actual",
71+
with => join(", ", "context");
72+
73+
reports:
74+
"Context '$(with)'; index $(range); expected '$(expected[$(range)])'; actual '$(actual[$(range)])'"
75+
with => join("', '", "context");
76+
ok::
77+
"$(this.promise_filename) Pass";
78+
!ok::
79+
"$(this.promise_filename) FAIL";
80+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
body common control
2+
{
3+
bundlesequence => { "check" };
4+
}
5+
6+
bundle agent test(context, index)
7+
{
8+
meta:
9+
"description" -> { "ENT-6193", "CFE-3421" }
10+
string => "Test for expected results from policy function classfilterdata() with array of objects using context '$(with)' and key $(key)",
11+
with => join("', '", "context");
12+
13+
vars:
14+
"test"
15+
data => '[
16+
{ "key_0": "foo", "key_1": "!foo", "key_2": "foo&bar", "key_3": "foo|bar" },
17+
{ "key_0": "bar", "key_1": "!bar", "key_2": "bar&baz", "key_3": "bar|baz" },
18+
{ "key_0": "baz", "key_1": "!baz", "key_2": "foo&baz", "key_3": "foo|baz" },
19+
]';
20+
21+
"actual"
22+
data => classfilterdata("@(test)", "array_of_objects", "key_$(index)");
23+
24+
classes:
25+
"$(context)";
26+
27+
reports:
28+
"$(with)"
29+
with => storejson("@(actual)"),
30+
bundle_return_value_index => "$(index)";
31+
}
32+
33+
bundle agent check
34+
{
35+
vars:
36+
"num_indices" string => "3";
37+
"context" slist => { "foo" };
38+
"range" slist => expandrange("[0-$(num_indices)]", "1");
39+
40+
"expected[0]"
41+
string => storejson('[
42+
{ "key_0": "foo", "key_1": "!foo", "key_2": "foo&bar", "key_3": "foo|bar" },
43+
]');
44+
"expected[1]"
45+
string => storejson('[
46+
{ "key_0": "bar", "key_1": "!bar", "key_2": "bar&baz", "key_3": "bar|baz" },
47+
{ "key_0": "baz", "key_1": "!baz", "key_2": "foo&baz", "key_3": "foo|baz" },
48+
]');
49+
"expected[2]"
50+
string => storejson('[
51+
]');
52+
"expected[3]"
53+
string => storejson('[
54+
{ "key_0": "foo", "key_1": "!foo", "key_2": "foo&bar", "key_3": "foo|bar" },
55+
{ "key_0": "baz", "key_1": "!baz", "key_2": "foo&baz", "key_3": "foo|baz" },
56+
]');
57+
58+
classes:
59+
"ok_$(range)"
60+
expression => strcmp("$(expected[$(range)])",
61+
"$(actual[$(range)])");
62+
"ok"
63+
expression => and(expandrange("ok_[0-$(num_indices)]", "1"));
64+
65+
methods:
66+
"context: '$(with)' and index: $(range)"
67+
usebundle => test("@(context)", "$(range)"),
68+
useresult => "actual",
69+
with => join(", ", "context");
70+
71+
reports:
72+
"Context '$(with)'; index $(range); expected '$(expected[$(range)])'; actual '$(actual[$(range)])'"
73+
with => join("', '", "context");
74+
ok::
75+
"$(this.promise_filename) Pass";
76+
!ok::
77+
"$(this.promise_filename) FAIL";
78+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
body common control
2+
{
3+
bundlesequence => { "check" };
4+
}
5+
6+
bundle agent test(context, index)
7+
{
8+
meta:
9+
"description" -> { "ENT-6193", "CFE-3421" }
10+
string => "Test for expected results from policy function classfilterdata() with array of objects using context '$(with)' and key $(key)",
11+
with => join("', '", "context");
12+
13+
vars:
14+
"test"
15+
data => '[
16+
{ "key_0": "foo", "key_1": "!foo", "key_2": "foo&bar", "key_3": "foo|bar" },
17+
{ "key_0": "bar", "key_1": "!bar", "key_2": "bar&baz", "key_3": "bar|baz" },
18+
{ "key_0": "baz", "key_1": "!baz", "key_2": "foo&baz", "key_3": "foo|baz" },
19+
]';
20+
21+
"actual"
22+
data => classfilterdata("@(test)", "array_of_objects", "key_$(index)");
23+
24+
classes:
25+
"$(context)";
26+
27+
reports:
28+
"$(with)"
29+
with => storejson("@(actual)"),
30+
bundle_return_value_index => "$(index)";
31+
}
32+
33+
bundle agent check
34+
{
35+
vars:
36+
"num_indices" string => "3";
37+
"context" slist => { "foo", "bar" };
38+
"range" slist => expandrange("[0-$(num_indices)]", "1");
39+
40+
"expected[0]"
41+
string => storejson('[
42+
{ "key_0": "foo", "key_1": "!foo", "key_2": "foo&bar", "key_3": "foo|bar" },
43+
{ "key_0": "bar", "key_1": "!bar", "key_2": "bar&baz", "key_3": "bar|baz" },
44+
]');
45+
"expected[1]"
46+
string => storejson('[
47+
{ "key_0": "baz", "key_1": "!baz", "key_2": "foo&baz", "key_3": "foo|baz" },
48+
]');
49+
"expected[2]"
50+
string => storejson('[
51+
{ "key_0": "foo", "key_1": "!foo", "key_2": "foo&bar", "key_3": "foo|bar" },
52+
]');
53+
"expected[3]"
54+
string => storejson('[
55+
{ "key_0": "foo", "key_1": "!foo", "key_2": "foo&bar", "key_3": "foo|bar" },
56+
{ "key_0": "bar", "key_1": "!bar", "key_2": "bar&baz", "key_3": "bar|baz" },
57+
{ "key_0": "baz", "key_1": "!baz", "key_2": "foo&baz", "key_3": "foo|baz" },
58+
]');
59+
60+
classes:
61+
"ok_$(range)"
62+
expression => strcmp("$(expected[$(range)])",
63+
"$(actual[$(range)])");
64+
"ok"
65+
expression => and(expandrange("ok_[0-$(num_indices)]", "1"));
66+
67+
methods:
68+
"context: '$(with)' and index: $(range)"
69+
usebundle => test("@(context)", "$(range)"),
70+
useresult => "actual",
71+
with => join(", ", "context");
72+
73+
reports:
74+
"Context '$(with)'; index $(range); expected '$(expected[$(range)])'; actual '$(actual[$(range)])'"
75+
with => join("', '", "context");
76+
ok::
77+
"$(this.promise_filename) Pass";
78+
!ok::
79+
"$(this.promise_filename) FAIL";
80+
}

0 commit comments

Comments
 (0)