gitlink-cli/shortcuts/workflow/rules/review_test.go

70 lines
1.6 KiB
Go

package rules
import (
"testing"
)
func TestCodeReviewStaticAnalysis(t *testing.T) {
upstream := map[string]interface{}{
"open-prs": map[string]interface{}{
"data": []interface{}{
map[string]interface{}{
"id": "1",
"title": "add feature",
"body": "password = 'hardcoded12345678'",
},
map[string]interface{}{
"id": "2",
"title": "wip",
"body": "",
"files_count": 60.0,
},
},
},
}
resp, err := CodeReviewRule(upstream, "review")
if err != nil {
t.Fatalf("CodeReviewRule failed: %v", err)
}
analysis := resp.Analysis.(map[string]interface{})
total := analysis["total_findings"].(int)
if total == 0 {
t.Fatal("expected findings for hardcoded password and large PR")
}
// Should have at least one high-severity security finding.
findings := analysis["findings"].([]finding)
hasSecurity := false
hasMaint := false
for _, f := range findings {
if f.Lens == "security" {
hasSecurity = true
}
if f.Lens == "maintainability" {
hasMaint = true
}
}
if !hasSecurity {
t.Error("expected security finding for hardcoded password")
}
if !hasMaint {
t.Error("expected maintainability finding for large PR or missing body")
}
}
func TestCodeReviewNoPRs(t *testing.T) {
upstream := map[string]interface{}{
"open-prs": map[string]interface{}{"data": []interface{}{}},
}
resp, err := CodeReviewRule(upstream, "review")
if err != nil {
t.Fatalf("CodeReviewRule failed: %v", err)
}
analysis := resp.Analysis.(map[string]interface{})
if msg := analysis["message"]; msg != "no open PRs to review" {
t.Fatalf("expected 'no open PRs to review', got %v", msg)
}
}