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/complete/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 = {
{"", {{"/", {{"Folder", "local"},
{"Folder", "test"},
{"Folder", "prod"}}},
{"/local/", {{"Table", "example"},
{"Table", "account"},
{"Table", "abacaba"}}},
{"/test/", {{"Folder", "service"},
{"Table", "meta"}}},
{"/test/service/", {{"Table", "example"}}}}},
};
return MakeSimpleSchema(MakeStaticSimpleSchema({.Folders = std::move(fs)}));
}
Y_UNIT_TEST(ListFolderBasic) {
auto schema = MakeStaticSchemaUT();
{
TVector<TFolderEntry> expected = {
{"Folder", "local"},
{"Folder", "test"},
{"Folder", "prod"},
};
UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/"}).GetValueSync().Entries, expected);
}
{
TVector<TFolderEntry> expected = {
{"Table", "example"},
{"Table", "account"},
{"Table", "abacaba"},
};
UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/local/"}).GetValueSync().Entries, expected);
}
{
TVector<TFolderEntry> expected = {
{"Folder", "service"},
{"Table", "meta"},
};
UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/test/"}).GetValueSync().Entries, expected);
}
{
TVector<TFolderEntry> expected = {
{"Table", "example"}};
UNIT_ASSERT_VALUES_EQUAL(schema->List({.Path = "/test/service/"}).GetValueSync().Entries, expected);
}
}
Y_UNIT_TEST(ListFolderHint) {
auto schema = MakeStaticSchemaUT();
{
TVector<TFolderEntry> expected = {
{"Folder", "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 = {
{"Table", "account"},
{"Table", "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 = {
{"Folder", "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 = {
{"Folder", "service"},
};
TListRequest request = {
.Path = "/test/",
.Filter = {
.Types = THashSet<TString>{"Folder"},
},
};
UNIT_ASSERT_VALUES_EQUAL(schema->List(request).GetValueSync().Entries, expected);
}
{
TVector<TFolderEntry> expected = {
{"Table", "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)
|