MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestSQLAnalyzer_InsertStatements

Function TestSQLAnalyzer_InsertStatements

cmd/gosqlx/cmd/sql_analyzer_test.go:470–522  ·  view source on GitHub ↗

TestSQLAnalyzer_InsertStatements tests analysis of INSERT statements

(t *testing.T)

Source from the content-addressed store, hash-verified

468
469// TestSQLAnalyzer_InsertStatements tests analysis of INSERT statements
470func TestSQLAnalyzer_InsertStatements(t *testing.T) {
471 tests := []struct {
472 name string
473 sql string
474 shouldSkip bool
475 }{
476 {
477 name: "simple INSERT",
478 sql: "INSERT INTO users (name, email) VALUES ('John', 'john@example.com')",
479 },
480 }
481
482 for _, tt := range tests {
483 t.Run(tt.name, func(t *testing.T) {
484 if tt.shouldSkip {
485 t.Skip("Parser doesn't fully support this INSERT syntax yet")
486 }
487
488 tkz := tokenizer.GetTokenizer()
489 defer tokenizer.PutTokenizer(tkz)
490
491 tokens, err := tkz.Tokenize([]byte(tt.sql))
492 if err != nil {
493 t.Fatalf("Tokenization failed: %v", err)
494 }
495
496 p := parser.NewParser()
497 astObj := ast.NewAST()
498 defer ast.ReleaseAST(astObj)
499
500 result, err := p.ParseFromModelTokens(tokens)
501 if err != nil {
502 t.Skipf("Parsing failed (expected for incomplete parser support): %v", err)
503 return
504 }
505 astObj.Statements = result.Statements
506
507 analyzer := NewSQLAnalyzer()
508 report, err := analyzer.Analyze(astObj)
509 if err != nil {
510 t.Fatalf("Analysis failed: %v", err)
511 }
512
513 // Basic validations
514 if report == nil {
515 t.Fatal("Expected report but got nil")
516 }
517 if report.SecurityScore < 0 || report.SecurityScore > 100 {
518 t.Errorf("Invalid security score: %d", report.SecurityScore)
519 }
520 })
521 }
522}
523
524// TestSQLAnalyzer_UpdateStatements tests analysis of UPDATE statements
525func TestSQLAnalyzer_UpdateStatements(t *testing.T) {

Callers

nothing calls this directly

Calls 12

ParseFromModelTokensMethod · 0.95
AnalyzeMethod · 0.95
GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
NewParserFunction · 0.92
NewASTFunction · 0.92
ReleaseASTFunction · 0.92
NewSQLAnalyzerFunction · 0.85
RunMethod · 0.80
TokenizeMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected