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
|
#include <library/cpp/testing/unittest/registar.h>
#include "yql_warning.h"
using namespace NYql;
Y_UNIT_TEST_SUITE(TWarningRuleTest) {
Y_UNIT_TEST(AllValidActionsAndPatternsAreParsed) {
TWarningRule rule;
TString errorMessage;
UNIT_ASSERT_VALUES_EQUAL(TWarningRule::ParseFrom("1234", "disable", rule, errorMessage), TWarningRule::EParseResult::PARSE_OK);
UNIT_ASSERT_VALUES_EQUAL(TWarningRule::ParseFrom("*", "error", rule, errorMessage), TWarningRule::EParseResult::PARSE_OK);
UNIT_ASSERT_VALUES_EQUAL(TWarningRule::ParseFrom("0", "default", rule, errorMessage), TWarningRule::EParseResult::PARSE_OK);
}
Y_UNIT_TEST(InvalidActionIsDetected) {
TWarningRule rule;
TString errorMessage;
UNIT_ASSERT_VALUES_EQUAL(TWarningRule::ParseFrom("1234", "wrong", rule, errorMessage), TWarningRule::EParseResult::PARSE_ACTION_FAIL);
UNIT_ASSERT_VALUES_EQUAL(TWarningRule::ParseFrom("1234", "", rule, errorMessage), TWarningRule::EParseResult::PARSE_ACTION_FAIL);
}
Y_UNIT_TEST(InvalidPatternIsDetected) {
TWarningRule rule;
TString errorMessage;
UNIT_ASSERT_VALUES_EQUAL(TWarningRule::ParseFrom("", "default", rule, errorMessage), TWarningRule::EParseResult::PARSE_PATTERN_FAIL);
UNIT_ASSERT_VALUES_EQUAL(TWarningRule::ParseFrom("-1", "default", rule, errorMessage), TWarningRule::EParseResult::PARSE_PATTERN_FAIL);
UNIT_ASSERT_VALUES_EQUAL(TWarningRule::ParseFrom("*1", "default", rule, errorMessage), TWarningRule::EParseResult::PARSE_PATTERN_FAIL);
UNIT_ASSERT_VALUES_EQUAL(TWarningRule::ParseFrom("default", "default", rule, errorMessage), TWarningRule::EParseResult::PARSE_PATTERN_FAIL);
}
}
void AddRule(TWarningPolicy& policy, const TString& codePattern, const TString& action)
{
TWarningRule rule;
TString errorMessage;
UNIT_ASSERT_VALUES_EQUAL(TWarningRule::ParseFrom(codePattern, action, rule, errorMessage), TWarningRule::EParseResult::PARSE_OK);
policy.AddRule(rule);
}
Y_UNIT_TEST_SUITE(TWarningPolicyTest) {
Y_UNIT_TEST(BasicIntegerRules) {
TWarningPolicy policy;
AddRule(policy, "123", "error");
AddRule(policy, "456", "error");
AddRule(policy, "456", "disable");
UNIT_ASSERT_VALUES_EQUAL(policy.GetRules().size(), 3);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(123), EWarningAction::ERROR);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(456), EWarningAction::DISABLE);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(111), EWarningAction::DEFAULT);
}
Y_UNIT_TEST(AsteriskRules) {
TWarningPolicy policy;
AddRule(policy, "*", "error");
AddRule(policy, "456", "disable");
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(999), EWarningAction::ERROR);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(456), EWarningAction::DISABLE);
AddRule(policy, "*", "default");
UNIT_ASSERT_VALUES_EQUAL(policy.GetRules().size(), 3);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(999), EWarningAction::DEFAULT);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(456), EWarningAction::DEFAULT);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(123), EWarningAction::DEFAULT);
}
Y_UNIT_TEST(ReactionOnPull) {
TWarningPolicy policy;
AddRule(policy, "*", "error");
AddRule(policy, "456", "default");
AddRule(policy, "999", "disable");
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(999), EWarningAction::DISABLE);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(456), EWarningAction::DEFAULT);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(123), EWarningAction::ERROR);
UNIT_ASSERT_VALUES_EQUAL(policy.GetRules().size(), 3);
policy.Clear();
UNIT_ASSERT_VALUES_EQUAL(policy.GetRules().size(), 0);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(999), EWarningAction::DEFAULT);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(456), EWarningAction::DEFAULT);
UNIT_ASSERT_VALUES_EQUAL(policy.GetAction(123), EWarningAction::DEFAULT);
}
}
|