MCPcopy Create free account
hub / github.com/github/gh-aw / TestRenderJSONWithFirewall

Function TestRenderJSONWithFirewall

pkg/cli/audit_test.go:741–828  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

739}
740
741func TestRenderJSONWithFirewall(t *testing.T) {
742 // Create test audit data with firewall analysis
743 firewallAnalysis := &FirewallAnalysis{
744 DomainBuckets: DomainBuckets{
745 AllowedDomains: []string{"api.github.com:443"},
746 BlockedDomains: []string{"blocked.example.com:443"},
747 },
748 TotalRequests: 10,
749 AllowedRequests: 7,
750 BlockedRequests: 3,
751 RequestsByDomain: map[string]DomainRequestStats{
752 "api.github.com:443": {Allowed: 7, Blocked: 0},
753 "blocked.example.com:443": {Allowed: 0, Blocked: 3},
754 },
755 }
756
757 auditData := AuditData{
758 Overview: OverviewData{
759 RunID: 123456,
760 WorkflowName: "Test Workflow",
761 Status: "completed",
762 Conclusion: "success",
763 Event: "push",
764 Branch: "main",
765 URL: "https://github.com/org/repo/actions/runs/123456",
766 },
767 Metrics: MetricsData{
768 TokenUsage: 1500,
769 Turns: 5,
770 ErrorCount: 0,
771 WarningCount: 0,
772 },
773 FirewallAnalysis: firewallAnalysis,
774 DownloadedFiles: []FileInfo{},
775 MissingTools: []MissingToolReport{},
776 MCPFailures: []MCPFailureReport{},
777 Errors: []ErrorInfo{},
778 Warnings: []ErrorInfo{},
779 ToolUsage: []ToolUsageInfo{},
780 }
781
782 // Render to JSON
783 oldStdout := os.Stdout
784 r, w, _ := os.Pipe()
785 os.Stdout = w
786
787 err := renderJSON(auditData)
788 w.Close()
789
790 // Read the output
791 var buf strings.Builder
792 io.Copy(&buf, r)
793 os.Stdout = oldStdout
794
795 if err != nil {
796 t.Fatalf("renderJSON failed: %v", err)
797 }
798

Callers

nothing calls this directly

Calls 4

renderJSONFunction · 0.85
CloseMethod · 0.65
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected