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

Function TestSQLAnalyzer_UpdateStatements

cmd/gosqlx/cmd/sql_analyzer_test.go:525–582  ·  view source on GitHub ↗

TestSQLAnalyzer_UpdateStatements tests analysis of UPDATE statements

(t *testing.T)

Source from the content-addressed store, hash-verified

523
524// TestSQLAnalyzer_UpdateStatements tests analysis of UPDATE statements
525func TestSQLAnalyzer_UpdateStatements(t *testing.T) {
526 tests := []struct {
527 name string
528 sql string
529 expectedMinSecScore int
530 }{
531 {
532 name: "UPDATE with WHERE",
533 sql: "UPDATE users SET active = true WHERE id = 1",
534 expectedMinSecScore: 70,
535 },
536 {
537 name: "UPDATE with complex WHERE",
538 sql: "UPDATE users SET status = 'active' WHERE created_at < '2023-01-01' AND verified = true",
539 expectedMinSecScore: 70,
540 },
541 }
542
543 for _, tt := range tests {
544 t.Run(tt.name, func(t *testing.T) {
545 tkz := tokenizer.GetTokenizer()
546 defer tokenizer.PutTokenizer(tkz)
547
548 tokens, err := tkz.Tokenize([]byte(tt.sql))
549 if err != nil {
550 t.Fatalf("Tokenization failed: %v", err)
551 }
552
553 p := parser.NewParser()
554 astObj := ast.NewAST()
555 defer ast.ReleaseAST(astObj)
556
557 result, err := p.ParseFromModelTokens(tokens)
558 if err != nil {
559 t.Skipf("Parsing failed (expected for incomplete parser support): %v", err)
560 return
561 }
562 astObj.Statements = result.Statements
563
564 analyzer := NewSQLAnalyzer()
565 report, err := analyzer.Analyze(astObj)
566 if err != nil {
567 t.Fatalf("Analysis failed: %v", err)
568 }
569
570 // Basic validations
571 if report == nil {
572 t.Fatal("Expected report but got nil")
573 }
574
575 // Check security score is reasonable
576 if report.SecurityScore < tt.expectedMinSecScore {
577 t.Errorf("Security score too low: expected >= %d, got %d",
578 tt.expectedMinSecScore, report.SecurityScore)
579 }
580 })
581 }
582}

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