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

Function readTestData

backend/tests/sql_review_test.go:408–444  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

406}
407
408func readTestData(path string) ([]test, error) {
409 yamlFile, err := os.Open(path)
410 if err != nil {
411 return nil, err
412 }
413 defer yamlFile.Close()
414 byteValue, err := io.ReadAll(yamlFile)
415 if err != nil {
416 return nil, err
417 }
418 type yamlStruct struct {
419 Statement string
420 Result []string
421 Run bool
422 }
423 var yamlTests []yamlStruct
424 if err := yaml.Unmarshal(byteValue, &yamlTests); err != nil {
425 return nil, err
426 }
427
428 var tests []test
429 for _, yamlTest := range yamlTests {
430 t := test{
431 Statement: yamlTest.Statement,
432 Run: yamlTest.Run,
433 }
434 for _, r := range yamlTest.Result {
435 result := &v1pb.PlanCheckRun_Result{}
436 if err := common.ProtojsonUnmarshaler.Unmarshal([]byte(r), result); err != nil {
437 return nil, err
438 }
439 t.Result = append(t.Result, result)
440 }
441 tests = append(tests, t)
442 }
443 return tests, nil
444}
445
446func writeTestData(filepath string, tests []test) error {
447 type yamlStruct struct {

Callers 2

TestSQLReviewForMySQLFunction · 0.85

Calls 3

UnmarshalMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected