Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Miryam-Schwartz committed Dec 10, 2024
1 parent b972bce commit 74c6af0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ufm_log_analyzer_ci_workflow.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Ufm log analyzer CI Workflow

on:
push:
pull_request:
paths:
- 'plugins/ufm_log_analyzer_plugin/**'
- '.github/workflows/ufm_log_analyzer_ci_workflow.yml'
Expand Down
13 changes: 13 additions & 0 deletions plugins/ufm_log_analyzer_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,17 @@ This logic will show links that:

![Tool flow](img/loganalzer.png)

## Testing

There is a folder named `unit_tests`, this folder contains some unit tests, to run the tests follow these steps:

1. Make sure you have `pytest` installed. If not, you can install it using `pip`:

```bash
pip install pytest
2. Navigate to the root directory of the log analyzer project:
```bash
cd plugins/ufm_log_analyzer_plugin
3. Run `pytest` to execute the tests:
```bash
pytest unit_tests
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,34 @@
# @author: Miryam Schwartz
# @date: Dec 08, 2024

import pytest
import sys
import os

sys.path.append(os.getcwd())
sys.path.append("/".join(os.getcwd().split("/")[:-1]))
sys.path.append("/".join(os.getcwd().split("/")[:-1]) + "/src")

import pytest
from unittest.mock import MagicMock

from loganalyze.log_analyzers.ibdiagnet_log_analyzer import IBDIAGNETLogAnalyzer


@pytest.fixture
def analyzer():
# Fixture to initialize the analyzer object
logs_csvs = []
hours = 24
dest_image_path = "/dummy/path"
return IBDIAGNETLogAnalyzer(logs_csvs, hours, dest_image_path)

def test_get_fabric_size(analyzer):
def analyzer(fabric_size_data):
# Mock the constructor of IBDIAGNETLogAnalyzer
mock_analyzer = MagicMock(spec=IBDIAGNETLogAnalyzer)

# Mock the _log_data_sorted attribute
expected_fabric_size = {"switch_count": 10, "link_count": 50} # Example data
analyzer._log_data_sorted = expected_fabric_size
mock_analyzer._log_data_sorted = fabric_size_data

# Mock the get_fabric_size method to return the _log_data_sorted attribute
mock_analyzer.get_fabric_size.return_value = fabric_size_data

# Return the mocked analyzer instance
return mock_analyzer

@pytest.fixture
def fabric_size_data():
# Shared mock data
return {"switch_count": 10, "link_count": 50}

def test_get_fabric_size(analyzer, fabric_size_data):
# Call the method and check the result
result = analyzer.get_fabric_size()
assert result == expected_fabric_size, "get_fabric_size should return _log_data_sorted"
assert result == fabric_size_data, "get_fabric_size should return _log_data_sorted"
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
# @date: Dec 08, 2024

import pytest
import sys
import os

sys.path.append(os.getcwd())
sys.path.append("/".join(os.getcwd().split("/")[:-1]))
sys.path.append("/".join(os.getcwd().split("/")[:-1]) + "/src")

from loganalyze.log_analyzers.ufm_top_analyzer import UFMTopAnalyzer

Expand Down

0 comments on commit 74c6af0

Please sign in to comment.