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

[2.0] Improve Testing Coverage #419

Merged
merged 65 commits into from
Jan 27, 2025
Merged

Conversation

strawgate
Copy link
Collaborator

@strawgate strawgate commented Dec 21, 2024

Non-test Changes

Test Changes

  • Switch to using the mock builder [2.0] Try out a mock builder #420
  • Add coverage for gateway init (basic, api, no auth, TLS, TLS with Custom CA, TLS without Hostname, No TLS) Improve Test Coverage to 97+% #280
  • Switch gateway to using a mock ES client
  • Switch config_flow to mocking the Gateway
  • Add coverage for datastream rollover on index template update
  • Add tests for connection testing state transitions
  • Add tests for connection issues during publishing
  • Improve system info coverage
  • Improve init coverage
Component Coverage Before Coverage After
init 90% 100%
es_datastream_manager 97% 100%
es_gateway 86% 100%
es_gateway_8 73% 100%
es_integration 85% 100%
es_publish_pipeline 91% 100%

Copy link
Contributor

github-actions bot commented Dec 21, 2024

Coverage

Coverage Report
FileStmtsMissCoverMissing
__init__.py00100% 
elasticsearch
   __init__.py1480100% 
   config_flow.py1580100% 
   const.py520100% 
   diagnostics.py80100% 
   encoder.py23291%42, 51
   entity_details.py1090100% 
   errors.py110100% 
   es_datastream_manager.py440100% 
   es_gateway.py1030100% 
   es_gateway_8.py1820100% 
   es_integration.py450100% 
   es_publish_pipeline.py3840100% 
   logger.py620100% 
   loop.py57296%31, 36
   system_info.py33584%34–37, 52
   utils.py27292%13, 24
elasticsearch/datastreams
   __init__.py20100% 
   index_template.py20100% 
TOTAL14501199% 

Tests Skipped Failures Errors Time
359 0 💤 0 ❌ 0 🔥 22.285s ⏱️

@strawgate strawgate enabled auto-merge (squash) December 21, 2024 18:44
@strawgate strawgate changed the title [2.0] Improve Coverage [2.0] Improve Testing Coverage Jan 9, 2025
@strawgate strawgate enabled auto-merge (squash) January 17, 2025 02:41
@strawgate
Copy link
Collaborator Author

@legrego I believe I am done with changes here

@legrego
Copy link
Owner

legrego commented Jan 24, 2025

@strawgate I get errors on startup when running this version on my HA box. In the past, HA required that all third-party import statements (elasticsearch/elasticsearch8 in our case) need to happen dynamically (within functions), as opposed to the top of the file. I don't know if that's related to what I'm seeing, I haven't spent the time to track this down yet:

Logger: homeassistant.setup
Source: setup.py:334
First occurred: 12:36:38 PM (1 occurrences)
Last logged: 12:36:38 PM

Setup failed for custom integration 'elasticsearch': Unable to import component: No module named 'elasticsearch'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 334, in _async_setup_component
    component = await integration.async_get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1035, in async_get_component
    self._component_future.result()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1015, in async_get_component
    comp = await self.hass.async_add_import_executor_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self._get_component, True
        ^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1075, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/config/custom_components/elasticsearch/__init__.py", line 8, in <module>
    from elasticsearch.const import ELASTIC_DOMAIN
ModuleNotFoundError: No module named 'elasticsearch'

@strawgate
Copy link
Collaborator Author

I know what causes this and I'm very surprised I didn't run into it -- I'll get this fixed and try to figure out why it's not happening on my instance

@strawgate
Copy link
Collaborator Author

@legrego I have fixed the namespace issue as we discussed. Sorry about that. I have verified my HA instance is using the latest commit here and is working now.

Copy link
Owner

@legrego legrego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested locally and all seems to be working as intended. Thanks!

from custom_components.elasticsearch.es_gateway_8 import Elasticsearch8Gateway, Gateway8Settings

# import custom_components.elasticsearch # noqa: F401
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, remove?

Suggested change
# import custom_components.elasticsearch # noqa: F401

Comment on lines +120 to +123
# @property
# def entity(self) -> RegistryEntry:
# """Return the Hass RegistryEntry object."""
# return self._entity
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# @property
# def entity(self) -> RegistryEntry:
# """Return the Hass RegistryEntry object."""
# return self._entity

@strawgate strawgate merged commit a54e5c2 into legrego:main Jan 27, 2025
3 checks passed
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.

2 participants