Skip to content

chore(testing): Add tests for Domain Reconciler#646

Merged
jonstacks merged 4 commits into
ngrok:mainfrom
jonstacks:mocking
May 6, 2025
Merged

chore(testing): Add tests for Domain Reconciler#646
jonstacks merged 4 commits into
ngrok:mainfrom
jonstacks:mocking

Conversation

@jonstacks

Copy link
Copy Markdown
Collaborator

What

This PR aims to help us improve our testing using envtest by creating a persistent mock for the ngrok reserved domains client. Eventually, we'll mock out more of the interfaces so that we do better integration testing of our Controllers and can maintain a list of automated regressions.

How

  • Create a mock that satisfies the ngrokapi.DomainClient interface. This mock persistently holds reserved domains and attempts to accurately return the same response that you would get from an actual client talking to ngrok. I've also added tests so that we can verify the mock behaves as we would expect.
  • Add tests for the DomainReconciler using the mock DomainClient to test common scenarios. There is a bit of a TODO here in that we aren't mocking things like transport errors. More work is needed to inject custom errors to test that the DomainReconciler gracefully handles those. However, this is a building block that will allow us to test applying Gateway, Ingress, or Load Balancer Service objects in envtest and validate that the correct items are provisioned handling any intermediate errors.

Breaking Changes

No, this is mostly adding better test coverage and allowing us to do better regression testing.

@jonstacks jonstacks self-assigned this May 6, 2025
@jonstacks jonstacks requested a review from a team as a code owner May 6, 2025 17:30
@github-actions github-actions Bot added area/controller Issues dealing with the controller and removed testing labels May 6, 2025
@codecov

codecov Bot commented May 6, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 87.28814% with 15 lines in your changes missing coverage. Please review.

Project coverage is 29.67%. Comparing base (7b82194) to head (e8ac626).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/mocks/nmockapi/domain_client.go 79.66% 9 Missing and 3 partials ⚠️
internal/mocks/nmockapi/base_client.go 94.59% 2 Missing ⚠️
api/ingress/v1alpha1/domain_types.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #646      +/-   ##
==========================================
+ Coverage   28.77%   29.67%   +0.89%     
==========================================
  Files          95       98       +3     
  Lines       15708    15825     +117     
==========================================
+ Hits         4520     4696     +176     
+ Misses      10924    10855      -69     
- Partials      264      274      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jonstacks jonstacks added this pull request to the merge queue May 6, 2025
Merged via the queue into ngrok:main with commit e93e96a May 6, 2025
10 checks passed
@jonstacks jonstacks deleted the mocking branch May 6, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/controller Issues dealing with the controller

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants