test: cover finding rules, model predicates, cost buckets, and region logic - #85
Merged
Conversation
… logic Coverage went from 140 to 205 tests across the four areas the issue names. All 25 finding rules are now exercised, up from 11. The added ones cover the pairs that must not double-report: production versus general secret rotation, stopped instances that look important versus merely unused, and idle load balancers versus failing ones. Model predicates gained tests on EC2, RDS, ELB, target groups, and SQS. These are the thresholds and boundaries the findings are built on: inclusive backlog thresholds, a low-CPU threshold that is exclusive at the boundary, unreadable tags never counting as a coverage gap, and saturating arithmetic that cannot underflow when a service reports more unhealthy targets than registered ones. Cost time-bucket logic had no tests at all. Covering it required making the window helpers take the date rather than reading the clock, which is also what let the December and year-boundary cases be tested at all. That surfaced a real bug, fixed here. Cost Explorer rejects a time period whose start and end are the same day, and the month-to-date window collapsed to exactly that on the first of every month, so all cost views reported the service unavailable that day. The window now covers the current day. Region selection gained tests for the synthetic global slot, exact and case-sensitive region matching, and the index clamp that keeps a stale index from reading past a shorter region list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #38.
A bug the tests found
Cost data failed to load on the first of every month.
month_to_date_fromreturned(first_of_month, today). On the 1st those are the same date, and Cost Explorer rejects that interval:I confirmed it against the live API rather than inferring it: the empty interval is rejected, a normal one is accepted. So on the 1st of each month every cost view reported Cost Explorer as unavailable, which would have looked like an intermittent permissions or outage problem.
Fixed by widening the window to cover the current day when it would otherwise collapse, verified against the live API for the 1st of a month, the 1st of January, and a mid-month control. All three now return real cost data.
Coverage
140 to 205 tests, across the four areas the issue names.
Finding rules: 11 of 25 exercised, now 25 of 25. The additions focus on the pairs that must not double-report, since that is where a rule change quietly breaks another: production versus general secret rotation, stopped instances that look important versus merely unused, idle load balancers versus failing ones, and zero-healthy versus partially-unhealthy target groups.
Model predicates: EC2, RDS, ELB, target groups, and SQS gained tests. These pin the boundaries the findings depend on:
healthy_targetssaturates, so a service reporting more unhealthy than registered targets cannot underflow into a huge countCost buckets: had no tests at all. Covering them meant making the window helpers take the date instead of reading the clock, which is also what makes the December rollover and year-boundary cases testable. There is a test asserting the six-month labels and the requested window agree, since a mismatch there silently offsets the chart axis from its data.
Region logic: the synthetic global slot (one past the real regions, and not selectable when none were discovered), exact case-sensitive region matching, and the index clamp that keeps a stale index from reading past a shorter region list.
Verification
cargo test: 205 passed, 0 failedcargo clippy --all-targets -- -D warnings: cleancargo fmt --check: cleanNote
Every test here passed on first run except one, which was my own invalid fixture date (29 February 2026, which does not exist; 2026 is not a leap year). So apart from the interval bug above, these tests confirm existing behavior rather than having uncovered further defects.