-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Core should support testing route handlers/controllers #51150
Comments
Pinging @elastic/kibana-platform (Team:Platform) |
Can plugins use existing test_utils? It can bootstrap the new platform. We need to provide recommendations on mocking core services (elasticsearch, saved objects) or a network layer. |
Reporting also uses this pattern for testing their legacy controllers: kibana/x-pack/legacy/plugins/reporting/server/routes/jobs.test.js Lines 82 to 96 in 8e9a8a8
|
done in #54908 |
Summary
@jloleysens and I discussed testing controllers and although workarounds were possible in Legacy, Core doesn't expose a way to test controller logic in an isolated way.
Details
The upgrade assistant plugin follows a fairly common pattern of "thin" controllers which handles the HTTP domain and glues together services which implement the business logic. Unit tests on the services themselves give good code coverage on the business logic, but still doesn't give full assurance that everything works as expected.
The legacy plugin created it's own Hapi server and registered the API routes / controllers to this server. This allowed the plugin to test the glue logic and API return codes using mocks for the underlying services. An alternative testing strategy would be to write these tests as functional tests, but this is hard and slow since testing the glue logic would require things like an Elasticsearch cluster which has nodes running different versions.
kibana/x-pack/legacy/plugins/upgrade_assistant/server/routes/reindex_indices.test.ts
Lines 32 to 57 in 7ac8e4d
@jloleysens got far by creating a testing router, but this still doesn't test everything a route/controller is responsible for:
kibana/x-pack/legacy/plugins/upgrade_assistant/server/np_ready/routes/__mocks__/routes.mock.ts
Lines 8 to 15 in 3046e54
Core should enable plugins to test their controllers:
The text was updated successfully, but these errors were encountered: