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

Function TestGetSchema_PrimaryKeyDerivation

backend/api/mcp/tool_schema_test.go:531–557  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

529}
530
531func TestGetSchema_PrimaryKeyDerivation(t *testing.T) {
532 usersTable := makeTable("users", 10,
533 []map[string]any{
534 makeColumn("id", "int4", false),
535 makeColumn("email", "varchar(255)", false),
536 makeColumn("created_at", "timestamptz", false),
537 },
538 []map[string]any{
539 makePrimaryKeyIndex("users_pkey", []string{"id"}),
540 makeIndex("users_email_idx", true, []string{"email"}), // unique but NOT primary
541 },
542 )
543 resp := makeMetadataResponse(makeSchema("public", usersTable))
544 s, _ := mockMetadataServer(t, employeeDB(), resp)
545
546 _, structured, err := s.handleGetSchema(testContext(), nil, SchemaInput{
547 Database: "employee_db",
548 Include: "columns",
549 })
550 require.NoError(t, err)
551 output, ok := structured.(*SchemaOutput)
552 require.True(t, ok)
553 cols := output.Schemas[0].Tables[0].Columns
554 require.True(t, cols[0].PrimaryKey, "id should be a PK (primary index)")
555 require.False(t, cols[1].PrimaryKey, "email should NOT be a PK (unique only)")
556 require.False(t, cols[2].PrimaryKey, "created_at should NOT be a PK")
557}
558
559func TestGetSchema_LimitForBulkModes(t *testing.T) {
560 resp := makeMetadataResponse(makeSchema("public",

Callers

nothing calls this directly

Calls 10

makePrimaryKeyIndexFunction · 0.85
makeMetadataResponseFunction · 0.85
mockMetadataServerFunction · 0.85
employeeDBFunction · 0.85
testContextFunction · 0.85
handleGetSchemaMethod · 0.80
makeTableFunction · 0.70
makeColumnFunction · 0.70
makeIndexFunction · 0.70
makeSchemaFunction · 0.70

Tested by

no test coverage detected