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

Function RunSplitTests

backend/plugin/parser/base/split_test_runner.go:118–144  ·  view source on GitHub ↗

RunSplitTests loads YAML test cases and runs them against a SplitSQL function. For engines with dual implementations (lexer and parser), it enforces that both produce identical results when both succeed. When run with -record flag, it updates the YAML file with actual results: go test -run TestXx

(t *testing.T, testDataPath string, opts SplitTestOptions)

Source from the content-addressed store, hash-verified

116//
117// go test -run TestXxxSplitSQL -args -record
118func RunSplitTests(t *testing.T, testDataPath string, opts SplitTestOptions) {
119 t.Helper()
120
121 require.NotNil(t, opts.SplitFunc, "SplitFunc is required")
122
123 // Get the full path to the test file
124 _, callerFile, _, ok := runtime.Caller(1)
125 require.True(t, ok, "failed to get caller info")
126 callerDir := filepath.Dir(callerFile)
127 fullPath := filepath.Join(callerDir, testDataPath)
128
129 // Caller depth 2: skip loadTestCases (1) and RunSplitTests (2) to get the actual test function
130 testCases := loadTestCases(t, testDataPath, 2)
131 require.NotEmpty(t, testCases, "no test cases found in %s", testDataPath)
132
133 // Record mode: update expected results in YAML file
134 if *record {
135 recordTestResults(t, fullPath, testCases, opts)
136 return
137 }
138
139 for _, tc := range testCases {
140 t.Run(tc.Description, func(t *testing.T) {
141 runSingleTest(t, tc, opts)
142 })
143 }
144}
145
146// recordTestResults runs all test cases and updates the YAML file with actual results.
147func recordTestResults(t *testing.T, fullPath string, testCases []SplitTestCase, opts SplitTestOptions) {

Callers 15

TestBigQuerySplitSQLFunction · 0.92
TestTrinoSplitSQLFunction · 0.92
TestStandardSplitSQLFunction · 0.92
TestRedshiftSplitSQLFunction · 0.92
TestCosmosDBSplitSQLFunction · 0.92
TestSpannerSplitSQLFunction · 0.92
TestMySQLSplitSQLFunction · 0.92
TestDorisSplitSQLFunction · 0.92
TestPLSQLSplitSQLFunction · 0.92
TestPartiQLSplitSQLFunction · 0.92
TestPGSplitSQLFunction · 0.92
TestStarRocksSplitSQLFunction · 0.92

Calls 5

loadTestCasesFunction · 0.85
recordTestResultsFunction · 0.85
runSingleTestFunction · 0.85
JoinMethod · 0.80
RunMethod · 0.45

Tested by 15

TestBigQuerySplitSQLFunction · 0.74
TestTrinoSplitSQLFunction · 0.74
TestStandardSplitSQLFunction · 0.74
TestRedshiftSplitSQLFunction · 0.74
TestCosmosDBSplitSQLFunction · 0.74
TestSpannerSplitSQLFunction · 0.74
TestMySQLSplitSQLFunction · 0.74
TestDorisSplitSQLFunction · 0.74
TestPLSQLSplitSQLFunction · 0.74
TestPartiQLSplitSQLFunction · 0.74
TestPGSplitSQLFunction · 0.74
TestStarRocksSplitSQLFunction · 0.74