aboutsummaryrefslogtreecommitdiffstats
path: root/ydb/core/fq/libs/common/util_ut.cpp
blob: 3e5a7d3e120229feab6d2ccc03fad18fb2ef3101 (plain) (blame)
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
#include "util.cpp"

#include <library/cpp/testing/unittest/registar.h>

namespace NFq {

Y_UNIT_TEST_SUITE(EscapingBasics) {
    Y_UNIT_TEST(EncloseSecretShouldWork) {
        UNIT_ASSERT_VALUES_EQUAL(EncloseSecret("some_secret1"), "/* 51a91b5d91a99eb7 */some_secret1/* e87c9b191b202354 */");
    }

    Y_UNIT_TEST(HideSecretsShouldWork) {
        UNIT_ASSERT_VALUES_EQUAL(HideSecrets("some text"), "some text");
        UNIT_ASSERT_VALUES_EQUAL(HideSecrets("/* 51a91b5d91a99eb7 */some_secret1/* e87c9b191b202354 */"), "/*SECRET*/");
        UNIT_ASSERT_VALUES_EQUAL(HideSecrets("/* 51a91b5d91a99eb7 */some_secret1/* e87c9b191b202354 */\n/* 51a91b5d91a99eb7 */some_secret2/* e87c9b191b202354 */"), "/*SECRET*/\n/*SECRET*/");
    }

    Y_UNIT_TEST(HideSecretsOverEncloseSecretShouldWork) {
        UNIT_ASSERT_VALUES_EQUAL(HideSecrets(EncloseSecret("some_secret1")), "/*SECRET*/");
    }

    Y_UNIT_TEST(EscapeStringShouldWork) {
        UNIT_ASSERT_VALUES_EQUAL(EscapeString("some_secret1", '"'), "some_secret1");
        UNIT_ASSERT_VALUES_EQUAL(EscapeString("some_secret1", "}+{", "[*]"), "some_secret1");
        UNIT_ASSERT_VALUES_EQUAL(EscapeString("some\"_\"secret1", '"'), "some\\\"_\\\"secret1");
        UNIT_ASSERT_VALUES_EQUAL(EscapeString("some}+{_}+{secret1", "}+{", "[*]"), "some[*]_[*]secret1");
    }

    Y_UNIT_TEST(EncloseAndEscapeStringShouldWork) {
        UNIT_ASSERT_VALUES_EQUAL(EncloseAndEscapeString("some_secret1", '"'), "\"some_secret1\"");
        UNIT_ASSERT_VALUES_EQUAL(EncloseAndEscapeString("some_secret1\nsome_secret2", "}+{", "[*]"), "}+{some_secret1\nsome_secret2}+{");

        UNIT_ASSERT_VALUES_EQUAL(EncloseAndEscapeString("some\"_\"secret1", '"'), "\"some\\\"_\\\"secret1\"");
        UNIT_ASSERT_VALUES_EQUAL(EncloseAndEscapeString("some_secret1}+{\n}+{some_secret2", "}+{", "[*]"), "}+{some_secret1[*]\n[*]some_secret2}+{");
    }
}

Y_UNIT_TEST_SUITE(IssuesTextFiltering) {
    Y_UNIT_TEST(ShouldRemoveDatabasePath) {
        TVector<NYql::TIssue> vecIssues;
        auto bottomIssue = MakeIntrusive<NYql::TIssue>("Error /path/to/database/binding_name db.[/path/to/database/binding_name]");
        auto midIssue = MakeIntrusive<NYql::TIssue>("'db.[/path/to/database/baz]' /path/to/database/foo /path/to/database/bar");
        midIssue->AddSubIssue(bottomIssue);
        NYql::TIssue topIssue("While doing smth db.[] /path/to/other/smth");
        topIssue.AddSubIssue(midIssue);
        NYql::TIssues issues({topIssue});

        TVector<NYql::TIssue> vecIssuesExpected;
        auto bottomIssueExpected = MakeIntrusive<NYql::TIssue>("Error binding_name binding_name");
        auto midIssueExpected = MakeIntrusive<NYql::TIssue>("'baz' foo bar");
        midIssueExpected->AddSubIssue(bottomIssueExpected);
        NYql::TIssue topIssueExpected("While doing smth db.[] /path/to/other/smth");
        topIssueExpected.AddSubIssue(midIssueExpected);
        NYql::TIssues issuesExpected({topIssueExpected});

        auto issuesActual = RemoveDatabaseFromIssues(issues, "/path/to/database");
        
        auto iterActual = issuesActual.begin();
        auto iterExpected = issuesExpected.begin();
        while (iterActual != issuesActual.end()) {
            UNIT_ASSERT_VALUES_EQUAL(*iterActual, *iterExpected);
            ++iterActual;
            ++iterExpected;
        }
    }
}

} // NFq