Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions test/internal/e2e/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ func Run(featureDir string, suiteInitializer func(*godog.TestSuiteContext), scen
path := os.Getenv("E2E_SUMMARY_OUTPUT")
if path == "" {
fmt.Println("Note: E2E_SUMMARY_OUTPUT is unset; skipping summary generation")
} else if err := summary.PrintSummary(path); err != nil {
// Alert but do not fail the run if alerts are found.
fmt.Printf("%v", err)
return 0
}
if err := summary.PrintSummary(path); err != nil {
// Only critical alerts (e.g. reconciler panics) return an error here;
// performance alerts over a threshold are informational and do not fail
// the run.
fmt.Printf("%v\n", err)
return 1
}
return 0
}
Expand Down
54 changes: 53 additions & 1 deletion test/internal/e2e/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,60 @@ func TestSummaryOutsideSuiteDirectory(t *testing.T) {
require.NoError(t, summary.PrintSummary(path))
content, err := os.ReadFile(path)
require.NoError(t, err)
require.Contains(t, string(content), "# E2E Summary")
require.Contains(t, string(content), "# 🧪 E2E Test Summary")
require.Contains(t, string(content), "operator-controller")
require.Contains(t, string(content), "catalogd")
require.Contains(t, string(content), "object-controller")
require.Contains(t, string(content), "xychart-beta")
}

// summaryServer serves a Prometheus-compatible response with the given alerts
// JSON (the contents of data.alerts) and a single-sample matrix for any query.
func summaryServer(t *testing.T, alertsJSON string) *httptest.Server {
t.Helper()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.URL.Path {
case "/api/v1/alerts":
fmt.Fprintf(w, `{"status":"success","data":{"alerts":[%s]}}`, alertsJSON)
case "/api/v1/query":
fmt.Fprint(w, `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{},"values":[[1,"1"]]}]}}`)
default:
http.NotFound(w, r)
}
}))
t.Cleanup(server.Close)
return server
}

func TestSummaryCriticalAlertFailsRun(t *testing.T) {
alertsJSON := `{"labels":{"alertname":"reconciler-panic","severity":"critical"},` +
`"annotations":{"description":"pod panicked"},"state":"firing","activeAt":"2026-12-02T10:30:00Z"}`
server := summaryServer(t, alertsJSON)
t.Setenv("PROMETHEUS_URL", server.URL)

path := filepath.Join(t.TempDir(), "summary.md")
err := summary.PrintSummary(path)
require.Error(t, err)
require.Contains(t, err.Error(), "reconciler-panic")

content, err := os.ReadFile(path)
require.NoError(t, err)
require.Contains(t, string(content), "critical alert(s) firing")
require.Contains(t, string(content), "reconciler-panic")
}

func TestSummaryWarningAlertDoesNotFailRun(t *testing.T) {
alertsJSON := `{"labels":{"alertname":"catalogd-cpu-usage","severity":"warning"},` +
`"annotations":{"description":"high cpu"},"state":"firing","activeAt":"2026-12-02T10:30:00Z"}`
server := summaryServer(t, alertsJSON)
t.Setenv("PROMETHEUS_URL", server.URL)

path := filepath.Join(t.TempDir(), "summary.md")
require.NoError(t, summary.PrintSummary(path))

content, err := os.ReadFile(path)
require.NoError(t, err)
require.Contains(t, string(content), "performance alert(s) over threshold")
require.Contains(t, string(content), "catalogd-cpu-usage")
}
Loading