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

Tests: Filenames returned by wcmatch prefixed with ./ cause fails #1836

Closed
sebix opened this issue Jan 28, 2022 · 0 comments · Fixed by #1837
Closed

Tests: Filenames returned by wcmatch prefixed with ./ cause fails #1836

sebix opened this issue Jan 28, 2022 · 0 comments · Fixed by #1837
Labels

Comments

@sebix
Copy link
Contributor

sebix commented Jan 28, 2022

Summary

It started with a test fail of this test case:
https://github.com/ansible-community/ansible-lint/blob/02de5a48b2a11f6305783d415e7117e41de05585/test/TestUtils.py#L329-L338
The stacktrace was:

[  414s] ________________________ test_discover_lintables_umlaut ________________________
[  414s] [gw6] linux -- Python 3.8.12 /usr/bin/python3.8
[  414s] 
[  414s] monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7feda277d8e0>
[  414s] 
[  414s]     def test_discover_lintables_umlaut(monkeypatch: MonkeyPatch) -> None:
[  414s]         """Verify that filenames containing German umlauts are not garbled by the discover_lintables."""
[  414s]         options = cli.get_config([])
[  414s]         test_dir = Path(__file__).resolve().parent
[  414s]         lint_path = test_dir / '..' / 'examples' / 'playbooks'
[  414s]     
[  414s]         monkeypatch.chdir(str(lint_path))
[  414s]         files = file_utils.discover_lintables(options)
[  414s]         assert '"with-umlaut-\\303\\244.yml"' not in files
[  414s] >       assert 'with-umlaut-ä.yml' in files
[  414s] E       AssertionError: assert 'with-umlaut-ä.yml' in OrderedDict([('./README.md', None), ('./always-run-success.yml', None), ('./become-user-without-become-failure.yml', N...yml', None), ('./vars/subfolder/settings.yml', None), ('./with-skip-tag-id.yml', None), ('./with-umlaut-ä.yml', None)])
[  414s] 
[  414s] files      = OrderedDict([('./README.md', None), ('./always-run-success.yml', None), ('./become-user-without-become-failure.yml', N...yml', None), ('./vars/subfolder/settings.yml', None), ('./with-skip-tag-id.yml', None), ('./with-umlaut-ä.yml', None)])
[  414s] lint_path  = PosixPath('/home/abuild/rpmbuild/BUILD/ansible-lint-5.3.2/test/../examples/playbooks')
[  414s] monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7feda277d8e0>
[  414s] options    = Namespace(colored=None, config_file='/home/abuild/rpmbuild/BUILD/ansible-lint-5.3.2/.ansible-lint', display_relative_p...tags=[], use_default_rules=True, verbosity=0, version=False, warn_list=['skip_this_tag', 'git-latest', 'experimental'])
[  414s] test_dir   = PosixPath('/home/abuild/rpmbuild/BUILD/ansible-lint-5.3.2/test')

In essence, the filenames returned by file_utils.discover_lintables are prefixed by ./ which is not expected by the test case and causes the fail.
The bug is in https://github.com/ansible-community/ansible-lint/blob/02de5a48b2a11f6305783d415e7117e41de05585/src/ansiblelint/file_utils.py#L223 because it assumes the output of git and the WcMatch is identical, but when WcMatch is called with ., the output is ./....

Will open a Pull Request with a fix.

Issue Type
  • Bug Report
Ansible and Ansible Lint details
ansible --version
2.9.27
ansible-lint --version
5.3.2
  • ansible installation method: OS package
  • ansible-lint installation method: source
OS / ENVIRONMENT

openSUSE Tumbleweed

STEPS TO REPRODUCE
  • Download the source, not using git, but with the tarball
  • run the tests
Desired Behaviour

Test succeed
Possible security bugs should be reported via email to security@ansible.com

Actual Behaviour

Test fails, see above

@sebix sebix added bug new Triage required labels Jan 28, 2022
sebix added a commit to sebix/ansible-lint that referenced this issue Jan 28, 2022
calling WcMatch('.', ...) causes the resulting file names to be prefixed
with `./`.
If the tests are run in a git-repository, this is not an issue, as git
is preferred of WcMatch in the code.

Therefore remove the `./` prefix from the WcMatch return value to get
the identical expected output.

fixes ansible#1836
sebix added a commit to sebix/ansible-lint that referenced this issue Jan 28, 2022
calling WcMatch('.', ...) causes the resulting file names to be prefixed
with `./`.
If the tests are run in a git-repository, this is not an issue, as git
is preferred of WcMatch in the code.

Therefore remove the `./` prefix from the WcMatch return value to get
the identical expected output.

fixes ansible#1836
sebix added a commit to sebix/ansible-lint that referenced this issue Jan 28, 2022
calling WcMatch('.', ...) causes the resulting file names to be prefixed
with `./`.
If the tests are run in a git-repository, this is not an issue, as git
is preferred of WcMatch in the code.

Therefore remove the `./` prefix from the WcMatch return value to get
the identical expected output.

fixes ansible#1836
@ssbarnea ssbarnea removed the new Triage required label Feb 1, 2022
sebix added a commit to sebix/ansible-lint that referenced this issue Feb 1, 2022
calling WcMatch('.', ...) causes the resulting file names to be prefixed
with `./`.
If the tests are run in a git-repository, this is not an issue, as git
is preferred of WcMatch in the code.

Therefore remove the `./` prefix from the WcMatch return value to get
the identical expected output.

fixes ansible#1836
sebix added a commit to sebix/ansible-lint that referenced this issue Feb 1, 2022
calling WcMatch('.', ...) causes the resulting file names to be prefixed
with `./`.
If the tests are run in a git-repository, this is not an issue, as git
is preferred of WcMatch in the code.

Therefore remove the `./` prefix from the WcMatch return value to get
the identical expected output.

fixes ansible#1836
sebix added a commit to sebix/ansible-lint that referenced this issue Feb 1, 2022
calling WcMatch('.', ...) causes the resulting file names to be prefixed
with `./`.
If the tests are run in a git-repository, this is not an issue, as git
is preferred of WcMatch in the code.

Therefore remove the `./` prefix from the WcMatch return value to get
the identical expected output.

fixes ansible#1836
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants