mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Setup module tests
This commit is contained in:
parent
c71afe35d6
commit
cb5929dad7
2 changed files with 31 additions and 3 deletions
|
@ -46,7 +46,7 @@ md5sum = None
|
||||||
if not os.path.exists(ansible_file):
|
if not os.path.exists(ansible_file):
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
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
|
# if facter is installed, and we can use --json because
|
||||||
# ruby-json is ALSO installed, include facter data in the JSON
|
# 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.write(reformat)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
md5sum2 = os.popen("md5sum %s" % ansible_file).read()
|
md5sum2 = os.popen("md5sum %s" % ansible_file).read().split()[0]
|
||||||
|
|
||||||
if md5sum != md5sum2:
|
if md5sum != md5sum2:
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
|
"written" : ansible_file,
|
||||||
"changed" : changed,
|
"changed" : changed,
|
||||||
"md5sum" : md5sum
|
"md5sum" : md5sum2
|
||||||
}
|
}
|
||||||
|
|
||||||
print json.dumps(result)
|
print json.dumps(result)
|
||||||
|
|
|
@ -9,6 +9,10 @@ import ansible.runner
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
|
try:
|
||||||
|
import json
|
||||||
|
except:
|
||||||
|
import simplejson as json
|
||||||
|
|
||||||
class TestRunner(unittest.TestCase):
|
class TestRunner(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -138,6 +142,20 @@ class TestRunner(unittest.TestCase):
|
||||||
assert 'failed' in result
|
assert 'failed' in result
|
||||||
assert 'rc' not 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):
|
def test_async(self):
|
||||||
# test async launch and job status
|
# test async launch and job status
|
||||||
# of any particular module
|
# of any particular module
|
||||||
|
@ -157,3 +175,12 @@ class TestRunner(unittest.TestCase):
|
||||||
assert 'stdout' in result
|
assert 'stdout' in result
|
||||||
assert result['ansible_job_id'] == jid
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue