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

Fix missing argument in test_macos_format_basic IT #1478

Merged
merged 4 commits into from
Jun 25, 2021

Conversation

spothound
Copy link
Contributor

@spothound spothound commented Jun 21, 2021

Related issue
Closes #1469

Description

It seems that format_macos_message_pattern' function arguments changed recently and were not updated in tests/integration/test_logcollector/test_macos/test_macos_format_basic.py leading to a logic failure because of a missing specification of the log type. This PR aims to fix that problem.

Configuration options

Tests

  • Proven that tests pass when they have to pass.
  • Proven that tests fail when they have to fail.
  • Python codebase satisfies PEP-8 style style guide. pycodestyle --max-line-length=120 --show-source --show-pep8 file.py.
  • Python codebase is documented following the Google Style for Python docstrings.
  • The test is documented in wazuh-qa/docs.
  • provision_documentation.sh generate the docs without errors.

@@ -45,7 +42,7 @@ def get_connection_configuration():
return logcollector.DEFAULT_AUTHD_REMOTED_SIMULATOR_CONFIGURATION


@pytest.mark.parametrize('macos_message', macos_log_messages)
@pytest.mark.parametrize('macos_message', macos_log_messages, ids=[x['id'] for x in macos_log_messages])
Copy link
Contributor

Choose a reason for hiding this comment

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

x["id"] don't use letters for arrays, use descriptive names, for examples: "id_list"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but actually the array is called macos_log_message. In this case the x refers to each element of this array. Each element has a map, that's why we use x['id], but yes, I've renamed it to log_message as each element of the array is a log message.

98d147f

snaow
snaow previously approved these changes Jun 22, 2021
@@ -760,4 +761,6 @@ def format_macos_message_pattern(process_name, message, type='log', subsystem=No
elif type == 'activity':
macos_message = f"{process_name}\[\d+\]: Created Activity ID.* Description: {message}"

assert macos_message is not None
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to put a message indicating the reason when the assert fails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -45,7 +42,7 @@ def get_connection_configuration():
return logcollector.DEFAULT_AUTHD_REMOTED_SIMULATOR_CONFIGURATION


@pytest.mark.parametrize('macos_message', macos_log_messages)
@pytest.mark.parametrize('macos_message', macos_log_messages, ids=[log_message['id'] for log_message in macos_log_messages])
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, check PEP-8 guide styleE501 line too long (124 > 120 characters)

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

expected_macos_message = logcollector.format_macos_message_pattern(
'custom_log',
logcollector.TEMPLATE_OSLOG_MESSAGE, macos_message['subsystem'],
logcollector.TEMPLATE_OSLOG_MESSAGE, 'log', macos_message['subsystem'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, check PEP-8 guide style`

E501 line too long (127 > 120 characters)

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logcollector.TEMPLATE_OSLOG_MESSAGE, 'log', macos_message['subsystem'],
logcollector.TEMPLATE_OSLOG_MESSAGE, subsystem=macos_message['subsystem'],

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use the name of the argument to specify its value instead of putting the rest of the preceding arguments one by one. Python is flexible in this topic.

Also, in this case 'log' is the default value, so it is not necessary .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

expected_macos_message = logcollector.format_macos_message_pattern(
'custom_log',
logcollector.TEMPLATE_OSLOG_MESSAGE, macos_message['subsystem'],
logcollector.TEMPLATE_OSLOG_MESSAGE, 'log', macos_message['subsystem'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logcollector.TEMPLATE_OSLOG_MESSAGE, 'log', macos_message['subsystem'],
logcollector.TEMPLATE_OSLOG_MESSAGE, subsystem=macos_message['subsystem'],

expected_macos_message = logcollector.format_macos_message_pattern(
'custom_log',
logcollector.TEMPLATE_OSLOG_MESSAGE, macos_message['subsystem'],
logcollector.TEMPLATE_OSLOG_MESSAGE, 'log', macos_message['subsystem'],
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use the name of the argument to specify its value instead of putting the rest of the preceding arguments one by one. Python is flexible in this topic.

Also, in this case 'log' is the default value, so it is not necessary .

@@ -479,6 +479,7 @@ def add_log_data(log_path, log_line_message, size_kib=1024, line_start=1, print_
return line_start + lines - 1
return 0


Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for pep8 requireements.

@spothound spothound requested review from jmv74211 and snaow and removed request for snaow and Rebits June 22, 2021 15:10
@snaow
Copy link
Contributor

snaow commented Jun 25, 2021

LGTM

@snaow snaow merged commit d665ab6 into master Jun 25, 2021
@snaow snaow deleted the 1469-fix-macos-logcollector-it branch June 25, 2021 09:28
@spothound
Copy link
Contributor Author

ty

@snaow snaow mentioned this pull request Jan 27, 2022
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.

Fix issues with macos logcollector IT in master branch
3 participants