From cb5929dad765ecdfc356b72ee1ffabfed72e7e87 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 4 Apr 2012 11:55:24 -0400 Subject: [PATCH] Setup module tests --- library/setup | 7 ++++--- test/TestRunner.py | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/library/setup b/library/setup index a79a8a9125..c5de2e9f22 100755 --- a/library/setup +++ b/library/setup @@ -46,7 +46,7 @@ md5sum = None if not os.path.exists(ansible_file): changed = True else: - md5sum = os.popen("md5sum %s" % ansible_file).read() + md5sum = os.popen("md5sum %s" % ansible_file).read().split()[0] # if facter is installed, and we can use --json because # ruby-json is ALSO installed, include facter data in the JSON @@ -91,14 +91,15 @@ reformat = json.dumps(new_options, sort_keys=True, indent=4) f.write(reformat) f.close() -md5sum2 = os.popen("md5sum %s" % ansible_file).read() +md5sum2 = os.popen("md5sum %s" % ansible_file).read().split()[0] if md5sum != md5sum2: changed = True result = { + "written" : ansible_file, "changed" : changed, - "md5sum" : md5sum + "md5sum" : md5sum2 } print json.dumps(result) diff --git a/test/TestRunner.py b/test/TestRunner.py index 9dcd330142..45ba5a745b 100644 --- a/test/TestRunner.py +++ b/test/TestRunner.py @@ -9,6 +9,10 @@ import ansible.runner import os import shutil import time +try: + import json +except: + import simplejson as json class TestRunner(unittest.TestCase): @@ -138,6 +142,20 @@ class TestRunner(unittest.TestCase): assert 'failed' in result assert 'rc' not in result + def test_setup(self): + output = self._get_stage_file('output.json') + result = self._run('setup', [ "metadata=%s" % output, "a=2", "b=3", "c=4" ]) + assert 'failed' not in result + assert 'md5sum' in result + assert result['changed'] == True + outds = json.loads(file(output).read()) + assert outds['c'] == '4' + # not bothering to test change hooks here since ohai/facter results change + # almost every time so changed is always true, this just tests that + # rewriting the file is ok + result = self._run('setup', [ "metadata=%s" % output, "a=2", "b=3", "c=4" ]) + assert 'md5sum' in result + def test_async(self): # test async launch and job status # of any particular module @@ -157,3 +175,12 @@ class TestRunner(unittest.TestCase): assert 'stdout' in result assert result['ansible_job_id'] == jid + def test_git(self): + # TODO: tests for the git module + pass + + def test_service(self): + # TODO: tests for the service module + pass + +