-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix running with role path containing single or multiple dirs (#390)
* Fix running with role path containing single or multiple dirs Signed-off-by: Andrew Crosby <acrosby@redhat.com> * Changed fix to check for role files inside rolepath dir Signed-off-by: Andrew Crosby <acrosby@redhat.com> * Add test case for role path deeper than 2 dirs Signed-off-by: Andrew Crosby <acrosby@redhat.com>
- Loading branch information
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import unittest | ||
import subprocess | ||
import os | ||
|
||
|
||
class TestCliRolePaths(unittest.TestCase): | ||
def setUp(self): | ||
self.local_test_dir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
def run_ansible_lint(self, cwd, bin, role_path): | ||
command = '{} {}'.format(bin, role_path) | ||
|
||
result, err = subprocess.Popen( | ||
[command], | ||
cwd=cwd, | ||
stdin=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
shell=True | ||
).communicate() | ||
|
||
self.assertFalse(err, 'Expected no error but was ' + str(err)) | ||
|
||
return result | ||
|
||
def test_run_single_role_path_no_trailing_slash(self): | ||
cwd = self.local_test_dir | ||
bin = '../bin/ansible-lint' | ||
role_path = 'test-role' | ||
|
||
result = self.run_ansible_lint(cwd=cwd, bin=bin, role_path=role_path) | ||
self.assertIn('Use shell only when shell functionality is required', | ||
str(result)) | ||
|
||
def test_run_single_role_path_with_trailing_slash(self): | ||
cwd = self.local_test_dir | ||
bin = '../bin/ansible-lint' | ||
role_path = 'test-role/' | ||
|
||
result = self.run_ansible_lint(cwd=cwd, bin=bin, role_path=role_path) | ||
self.assertIn('Use shell only when shell functionality is required', | ||
str(result)) | ||
|
||
def test_run_multiple_role_path_no_trailing_slash(self): | ||
cwd = self.local_test_dir | ||
bin = '../bin/ansible-lint' | ||
role_path = 'roles/test-role' | ||
|
||
result = self.run_ansible_lint(cwd=cwd, bin=bin, role_path=role_path) | ||
self.assertIn('Use shell only when shell functionality is required', | ||
str(result)) | ||
|
||
def test_run_multiple_role_path_with_trailing_slash(self): | ||
cwd = self.local_test_dir | ||
bin = '../bin/ansible-lint' | ||
role_path = 'roles/test-role/' | ||
|
||
result = self.run_ansible_lint(cwd=cwd, bin=bin, role_path=role_path) | ||
self.assertIn('Use shell only when shell functionality is required', | ||
str(result)) | ||
|
||
def test_run_inside_role_dir(self): | ||
cwd = os.path.join(self.local_test_dir, 'test-role/') | ||
bin = '../../bin/ansible-lint' | ||
role_path = '.' | ||
|
||
result = self.run_ansible_lint(cwd=cwd, bin=bin, role_path=role_path) | ||
self.assertIn('Use shell only when shell functionality is required', | ||
str(result)) | ||
|
||
def test_run_role_three_dir_deep(self): | ||
cwd = self.local_test_dir | ||
bin = '../bin/ansible-lint' | ||
role_path = 'roles/roles/test-role' | ||
|
||
result = self.run_ansible_lint(cwd=cwd, bin=bin, role_path=role_path) | ||
self.assertIn('Use shell only when shell functionality is required', | ||
str(result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- name: shell instead of command | ||
shell: echo hello world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- name: shell instead of command | ||
shell: echo hello world |