MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestGetResourcesTiDB

Function TestGetResourcesTiDB

backend/component/export/export_test.go:323–386  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

321}
322
323func TestGetResourcesTiDB(t *testing.T) {
324 a := assert.New(t)
325 ctx := context.Background()
326
327 instance := &store.InstanceMessage{
328 ResourceID: "test-tidb-instance",
329 Metadata: &storepb.Instance{
330 Engine: storepb.Engine_TIDB,
331 },
332 }
333
334 getDatabaseMetadataFunc := func(_ context.Context, _ string, _ string) (string, *model.DatabaseMetadata, error) {
335 dbMeta := model.NewDatabaseMetadata(
336 &storepb.DatabaseSchemaMetadata{
337 Name: "",
338 Schemas: []*storepb.SchemaMetadata{
339 {
340 Name: "",
341 Tables: []*storepb.TableMetadata{
342 {
343 Name: "cbt_plans",
344 Columns: []*storepb.ColumnMetadata{
345 {Name: "id", Type: "bigint"},
346 },
347 },
348 },
349 },
350 },
351 },
352 nil,
353 nil,
354 storepb.Engine_TIDB,
355 false,
356 )
357 return "", dbMeta, nil
358 }
359
360 listDatabaseNamesFunc := func(_ context.Context, _ string) ([]string, error) {
361 return nil, nil
362 }
363
364 getLinkedDatabaseMetadataFunc := func(_ context.Context, _, _, _ string) (string, string, *model.DatabaseMetadata, error) {
365 return "", "", nil, nil
366 }
367
368 // With databaseName = "":
369 // - If TiDB hits default case: returns error "database must be specified"
370 // - If TiDB hits MySQL case: calls GetQuerySpan and returns resources
371 resources, err := GetResources(
372 ctx,
373 nil,
374 storepb.Engine_TIDB,
375 "",
376 "SELECT id FROM cbt_plans;",
377 instance,
378 getDatabaseMetadataFunc,
379 listDatabaseNamesFunc,
380 getLinkedDatabaseMetadataFunc,

Callers

nothing calls this directly

Calls 4

NewDatabaseMetadataFunction · 0.92
GetResourcesFunction · 0.85
LenMethod · 0.80
EqualMethod · 0.65

Tested by

no test coverage detected