Skip to content

Commit

Permalink
Removed apt_key tests, as they didn't test the real functionality.
Browse files Browse the repository at this point in the history
Tests used heavily mocked version of the apt_key code, which meant that
it didn't properly test real life scenario.
  • Loading branch information
jlitola committed Jan 25, 2013
1 parent 05f5b5b commit 2796603
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 110 deletions.
50 changes: 0 additions & 50 deletions library/apt_key
Original file line number Diff line number Diff line change
Expand Up @@ -121,56 +121,6 @@ def return_values(tb=False):
else:
return {}


# use cues from the environment to mock out functions for testing
if 'ANSIBLE_TEST_APT_KEY' in environ:
orig_download_key = download_key
KEY_ADDED=0
KEY_REMOVED=0
KEY_DOWNLOADED=0


def download_key(url):
global KEY_DOWNLOADED
KEY_DOWNLOADED += 1
return orig_download_key(url)


def find_missing_binaries():
return []


def add_key(key):
global KEY_ADDED
KEY_ADDED += 1
return True


def remove_key(key_id):
global KEY_REMOVED
KEY_REMOVED += 1
return True


def return_values(tb=False):
extra = dict(
added=KEY_ADDED,
removed=KEY_REMOVED,
downloaded=KEY_DOWNLOADED
)
if tb:
extra['exception'] = format_exc()
return extra


if environ.get('ANSIBLE_TEST_APT_KEY') == 'none':
def key_present(key_id):
return False
else:
def key_present(key_id):
return key_id == environ['ANSIBLE_TEST_APT_KEY']


def main():
module = AnsibleModule(
argument_spec=dict(
Expand Down
60 changes: 0 additions & 60 deletions test/TestRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,63 +290,3 @@ def test_assemble(self):
print result
assert result['changed'] == False

def test_apt_key(self):
try:
key_file = self._get_test_file("apt_key.gpg")
key_file_url = 'file://' + urllib2.quote(key_file)
key_id = '473041FA'

os.environ['ANSIBLE_TEST_APT_KEY'] = 'none'
# key missing, should download and add
result = self._run('apt_key', ['state=present', 'url=' + key_file_url])
assert 'failed' not in result
assert result['added'] == 1
assert result['downloaded'] == 1
assert result['removed'] == 0
assert result['changed']

os.environ["ANSIBLE_TEST_APT_KEY"] = key_id
# key missing, shouldn't download, no changes
result = self._run('apt_key', ['id=12345678', 'state=absent', 'url=' + key_file_url])
assert 'failed' not in result
assert result['added'] == 0
assert result['downloaded'] == 0
assert result['removed'] == 0
assert not result['changed']
# key missing, should download and fail sanity check, no changes
result = self._run('apt_key', ['id=12345678', 'state=present', 'url=' + key_file_url])
assert 'failed' in result
assert result['added'] == 0
assert result['downloaded'] == 1
assert result['removed'] == 0
# key present, shouldn't download, no changes
result = self._run('apt_key', ['id=' + key_id, 'state=present', 'url=' + key_file_url])
assert 'failed' not in result
assert result['added'] == 0
assert result['downloaded'] == 0
assert result['removed'] == 0
assert not result['changed']
# key present, should download to get key id
result = self._run('apt_key', ['state=present', 'url=' + key_file_url])
assert 'failed' not in result
assert result['added'] == 0
assert result['downloaded'] == 1
assert result['removed'] == 0
assert not result['changed']
# key present, should download to get key id and remove
result = self._run('apt_key', ['state=absent', 'url=' + key_file_url])
assert 'failed' not in result
assert result['added'] == 0
assert result['downloaded'] == 1
assert result['removed'] == 1
assert result['changed']
# key present, should remove but not download
result = self._run('apt_key', ['id=' + key_id, 'state=absent', 'url=' + key_file_url])
assert 'failed' not in result
assert result['added'] == 0
assert result['downloaded'] == 0
assert result['removed'] == 1
assert result['changed']
finally:
# always clean up the environment
os.environ.pop('ANSIBLE_TEST_APT_KEY', None)

0 comments on commit 2796603

Please sign in to comment.