Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the test coverage for the fpm-server-requirement-status endpoint. #9708

Open
1 task
techanvil opened this issue Nov 19, 2024 · 0 comments
Open
1 task
Labels
P2 Low priority Type: Infrastructure Engineering infrastructure & tooling

Comments

@techanvil
Copy link
Collaborator

techanvil commented Nov 19, 2024

Feature Description

The initial implementation of the test coverage for the fpm-server-requirement-status (see #9632) involved mocking the is_endpoint_healthy() protected method of the REST_First_Party_Mode_Controller, due to difficulty testing the code contained within the method.

Notably, although it's possible to mock file_get_contents(), it doesn't appear possible to mock the $http_response_header that gets set locally in the file_get_contents() caller's scope with off the shelf tooling.

// Here we mock the `is_endpoint_healthy()` method of the controller. This is necessary because, although we could
// mock `file_get_contents()`, it's not possible to mock the `$http_response_header` variable used within the scope
// of the `is_endpoint_healthy()` method. The rest of the controller's behaviour remains unmocked.
$mock_controller = $this->getMockBuilder( REST_First_Party_Mode_Controller::class )
->setConstructorArgs( array( $this->settings ) )
->onlyMethods( array( 'is_endpoint_healthy' ) )
->getMock();

We should improve the test coverage to ensure the code contained in is_endpoint_healthy() is covered. Possible angles include:

  • Refactoring REST_First_Party_Mode_Controller so we pass in say a Guzzle client instance, or our own wrapper to file_get_contents(), and use that rather than calling file_get_contents() directly, allowing us to pass in a mock client during testing and avoid mocking is_endpoint_healthy().
  • Adding E2E test coverage for the endpoint. This comes with its own challenges, notably mocking the health check to https://g-1234.fps.goog/mpath/healthy to avoid calling the real Google service from our E2E tests. It looks possible, but would involve some structural changes to our E2E test environment; this was explored during the implementation of 9632, see Add fpm-server-requirement-status E2E test (draft). #9707. A more practical approach requiring less structural changes would be to provide filters for the health check URLs so we could override them during testing. However, the REST_First_Party_Mode_Controller described above is probably the best way to proceed here.

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

Test Coverage

QA Brief

Changelog entry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Low priority Type: Infrastructure Engineering infrastructure & tooling
Projects
None yet
Development

No branches or pull requests

1 participant