MCPcopy Index your code
hub / github.com/bytebase/bytebase / TestGetAccessTables

Function TestGetAccessTables

backend/plugin/parser/plsql/query_span_test.go:187–239  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

185}
186
187func TestGetAccessTables(t *testing.T) {
188 tests := []struct {
189 statement string
190 expected []base.SchemaResource
191 }{
192 {
193 statement: "SELECT * FROM t1 WHERE c1 = 1",
194 expected: []base.SchemaResource{
195 {
196 Database: "DB",
197 Table: "T1",
198 },
199 },
200 },
201 {
202 statement: "SELECT * FROM schema1.t1 JOIN schema2.t2 ON t1.c1 = t2.c1;",
203 expected: []base.SchemaResource{
204 {
205 Database: "SCHEMA1",
206 Table: "T1",
207 },
208 {
209 Database: "SCHEMA2",
210 Table: "T2",
211 },
212 },
213 },
214 {
215 statement: "SELECT a > (select max(a) from t1) FROM t2;",
216 expected: []base.SchemaResource{
217 {
218 Database: "DB",
219 Table: "T1",
220 },
221 {
222 Database: "DB",
223 Table: "T2",
224 },
225 },
226 },
227 }
228
229 for _, test := range tests {
230 results, err := ParsePLSQLOmni(test.statement)
231 require.NoError(t, err)
232 require.NotEmpty(t, results)
233 require.NotEmpty(t, results.Items)
234 raw, ok := results.Items[0].(*oracleast.RawStmt)
235 require.True(t, ok)
236 resources := collectOmniAccessTables("DB", raw.Stmt)
237 require.Equal(t, test.expected, resources, test.statement)
238 }
239}

Callers

nothing calls this directly

Calls 3

ParsePLSQLOmniFunction · 0.85
collectOmniAccessTablesFunction · 0.70
EqualMethod · 0.65

Tested by

no test coverage detected