Skip to content

test(grafana): add comprehensive tests for API clients#7528

Open
andreahlert wants to merge 1 commit intobackstage:mainfrom
andreahlert:test/grafana-api-client-tests
Open

test(grafana): add comprehensive tests for API clients#7528
andreahlert wants to merge 1 commit intobackstage:mainfrom
andreahlert:test/grafana-api-client-tests

Conversation

@andreahlert
Copy link
Contributor

Summary

Adds comprehensive unit tests for GrafanaApiClient and UnifiedAlertingGrafanaApiClient, which previously had zero test coverage.

33 new test cases organized in the following categories:

GrafanaApiClient (legacy alerting)

  • Dashboard listing: tag-based search, query expression evaluation, URL qualification, folderTitle defaults, hyphenated tags
  • Alert fetching: field mapping, URL construction with panelId/fullscreen params, dashboardTag parameter, empty results
  • Error handling: 403 Forbidden, 500 Internal Server Error
  • Proxy configuration: default /grafana/api path, custom proxy path
  • Pagination: single page default, multi-page fetching, early stop on partial pages, upstream limit cap (5000), max pages safety limit

UnifiedAlertingGrafanaApiClient (unified alerting)

  • Dashboard listing: delegates to shared search logic
  • Alert fetching: single string selector, multiple selectors array, endpoint verification, no-match handling, rules without labels
  • State aggregation: Alerting priority, Error priority, Pending priority, all-NoData, all-Normal, Normal+NoData mix, unrecognized states fallback to n/a, Alerting > Error priority ordering

Test plan

  • All 33 new tests pass locally
  • Full test suite (7 suites, 46 tests) passes with zero regressions
  • ESLint passes on new test file
  • Pre-commit hooks pass (eslint --fix, prettier --write)

@andreahlert andreahlert requested a review from a team as a code owner February 8, 2026 10:34
@andreahlert andreahlert requested review from Parsifal-M and removed request for a team February 8, 2026 10:34
@backstage-goalie
Copy link
Contributor

Thanks for the contribution!
All commits need to be DCO signed before they are reviewed. Please refer to the the DCO section in CONTRIBUTING.md or the DCO status for more info.

Add unit tests for GrafanaApiClient and UnifiedAlertingGrafanaApiClient
covering dashboard listing, alert fetching, proxy path configuration,
pagination behavior, error handling, and alert state aggregation logic.

33 new test cases covering previously untested API client functionality.

Signed-off-by: André Ahlert <andre@aex.partners>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants