Skip to content

Add unit tests for reportUnmatchedStopClusters - #86

Open
Vishmayraj wants to merge 1 commit into
OneBusAway:mainfrom
Vishmayraj:main
Open

Add unit tests for reportUnmatchedStopClusters#86
Vishmayraj wants to merge 1 commit into
OneBusAway:mainfrom
Vishmayraj:main

Conversation

@Vishmayraj

Copy link
Copy Markdown

stop_clusters.go was the only file in internal/metrics/ without a
corresponding test file.

This PR adds stop_clusters_test.go covering the following cases:

  • Empty stop map reports no metrics
  • Stop with no parent and valid coordinates uses S2 clustering
  • Station type stop clusters by its own ID
  • Malformed stop with no parent and no coordinates is skipped
  • Multiple stops in the same station cluster are aggregated correctly

All existing tests continue to pass.

@CLAassistant

CLAassistant commented Mar 12, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@aaronbrethorst

Copy link
Copy Markdown
Member

Code review

Found 1 issue:

  1. Three of the five subtests contain no assertions, so they pass no matter what reportUnmatchedStopClusters does. "Empty map reports no metrics" and "Malformed stop with no parent and no coords is skipped" (L56-L66) never check that nothing was reported — getClusterID returns ok=false on both paths without any possibility of a panic, so these two cases cannot fail under any implementation. "Stop with no parent and valid coords uses S2 clustering" is the only subtest covering the S2 branch and it asserts nothing either; the comment says full validation "would require knowing the S2 cell ID at runtime", but the S2 cell ID is not needed — gathering UnmatchedStopClusterCount (e.g. testutil.CollectAndCount, or iterating the collected dto.Metric families) is enough to assert that exactly one series exists for server-1 with cluster_type="s2", and that no series exists for server-3. As written, the S2 path — the most interesting untested branch — is still uncovered.

t.Run("Empty map reports no metrics", func(t *testing.T) {
// Should not panic or error
reportUnmatchedStopClusters("server-1", "agency-1", map[string]remoteGtfs.Stop{})
})
t.Run("Stop with no parent and valid coords uses S2 clustering", func(t *testing.T) {
stops := map[string]remoteGtfs.Stop{
"stop-1": {
Id: "stop-1",
Type: 0,
Latitude: float64Ptr(47.6062),
Longitude: float64Ptr(-122.3321),
},
}
reportUnmatchedStopClusters("server-1", "agency-1", stops)
// Metric should be set, we just verify no panic and the gauge exists
// Full label validation would require knowing the S2 cell ID at runtime
})

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants