nickjj / rolespec

A test library for testing Ansible roles
GNU General Public License v3.0
232 stars 20 forks source link

Fixes assert_in_file and adds iptable rules #19

Closed leucos closed 9 years ago

leucos commented 9 years ago

Some systems come with empty iptables rules. In this context, the assert_iptables_allow "tcp" test would fail. This patch adds a rule during test setup, and removes it at test teardown so the aformentionned test can match something.

In the 'negate' part of the function, assert_in_file was previously written as bash && fail || pass chain. However, since fail() exits with 1, the 'or' (||) part was always executed too. So when assert_in_file was called with a string that WAS in the file (and thus, was supposed to returl FAIL), il always returns two tests results (FAIL, then PASS). The logic has been changed so only fail xor pass is now called.

However, since rolespec own test suite rely on displaying 'FAIL' or 'PASS' in the console, there is currently no way to write a regression test for rolespec own test suite, since it would mean writing, on purpose, a test that fails and check that the test indeed FAILs (and doesn't FAIL and then PASS), which is not possible.

nickjj commented 9 years ago

Looks good, thanks for catching these issues.