summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/ide/completion/name/object/simple/schema_ut.cpp
blob: 2e045ef05956e4bb51ebd8d3ef1fc117cc8959b7 (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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "schema.h"

#include <yql/essentials/sql/v1/ide/completion/name/object/simple/static/schema.h>

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

using namespace NSQLComplete;

Y_UNIT_TEST_SUITE(StaticSchemaTests) {

ISchema::TPtr MakeStaticSchemaUT() {
    THashMap<TString, THashMap<TString, TVector<TFolderEntry>>> fs = {
        {"", {{"/", {{.Type = "Folder", .Name = "local"},
                     {.Type = "Folder", .Name = "test"},
                     {.Type = "Folder", .Name = "prod"}}},
              {"/local/", {{.Type = "Table", .Name = "example"},
                           {.Type = "Table", .Name = "account"},
                           {.Type = "Table", .Name = "abacaba"}}},
              {"/test/", {{.Type = "Folder", .Name = "service"},
                          {.Type = "Table", .Name = "meta"}}},
              {"/test/service/", {{.Type = "Table", .Name = "example"}}}}},
    };
    return MakeSimpleSchema(MakeStaticSimpleSchema({.Folders = std::move(fs)}));
}

Y_UNIT_TEST(ListFolderBasic) {
    auto schema = MakeStaticSchemaUT();
    {
        TVector<TFolderEntry> expected = {
            {.Type = "Folder", .Name = "local"},
            {.Type = "Folder", .Name = "test"},
            {.Type = "Folder", .Name = "prod"},
        };
        UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/"}).GetValueSync().Entries, expected);
    }
    {
        TVector<TFolderEntry> expected = {
            {.Type = "Table", .Name = "example"},
            {.Type = "Table", .Name = "account"},
            {.Type = "Table", .Name = "abacaba"},
        };
        UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/local/"}).GetValueSync().Entries, expected);
    }
    {
        TVector<TFolderEntry> expected = {
            {.Type = "Folder", .Name = "service"},
            {.Type = "Table", .Name = "meta"},
        };
        UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/test/"}).GetValueSync().Entries, expected);
    }
    {
        TVector<TFolderEntry> expected = {
            {.Type = "Table", .Name = "example"}};
        UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/test/service/"}).GetValueSync().Entries, expected);
    }
}

Y_UNIT_TEST(ListFolderHint) {
    auto schema = MakeStaticSchemaUT();
    {
        TVector<TFolderEntry> expected = {
            {.Type = "Folder", .Name = "local"},
        };
        auto actual = schema->List({.Path = "/l"}).GetValueSync();
        UNIT_ASSERT_VALUES_EQUAL(actual.Entries, expected);
        UNIT_ASSERT_VALUES_EQUAL(actual.NameHintLength, 1);
    }
    {
        TVector<TFolderEntry> expected = {
            {.Type = "Table", .Name = "account"},
            {.Type = "Table", .Name = "abacaba"},
        };
        auto actual = schema->List({.Path = "/local/a"}).GetValueSync();
        UNIT_ASSERT_VALUES_EQUAL(actual.Entries, expected);
        UNIT_ASSERT_VALUES_EQUAL(actual.NameHintLength, 1);
    }
    {
        TVector<TFolderEntry> expected = {
            {.Type = "Folder", .Name = "service"},
        };
        auto actual = schema->List({.Path = "/test/service"}).GetValueSync();
        UNIT_ASSERT_VALUES_EQUAL(actual.Entries, expected);
        UNIT_ASSERT_VALUES_EQUAL(actual.NameHintLength, 7);
    }
}

Y_UNIT_TEST(ListFolderFilterByType) {
    auto schema = MakeStaticSchemaUT();
    {
        TVector<TFolderEntry> expected = {
            {.Type = "Folder", .Name = "service"},
        };
        TListRequest request = {
            .Path = "/test/",
            .Filter = {
                .Types = THashSet<TString>{"Folder"},
            },
        };
        UNIT_ASSERT_VALUES_EQUAL(schema->List(request).GetValueSync().Entries, expected);
    }
    {
        TVector<TFolderEntry> expected = {
            {.Type = "Table", .Name = "meta"},
        };
        TListRequest request = {
            .Path = "/test/",
            .Filter = {
                .Types = THashSet<TString>{"Table"},
            },
        };
        UNIT_ASSERT_VALUES_EQUAL(schema->List(request).GetValueSync().Entries, expected);
    }
}

Y_UNIT_TEST(ListFolderLimit) {
    auto schema = MakeStaticSchemaUT();
    UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/", .Limit = 0}).GetValueSync().Entries.size(), 0);
    UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/", .Limit = 1}).GetValueSync().Entries.size(), 1);
    UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/", .Limit = 2}).GetValueSync().Entries.size(), 2);
    UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/", .Limit = 3}).GetValueSync().Entries.size(), 3);
    UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/", .Limit = 4}).GetValueSync().Entries.size(), 3);
    UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/", .Limit = 5}).GetValueSync().Entries.size(), 3);
}

} // Y_UNIT_TEST_SUITE(StaticSchemaTests)