From 6a5f9082698f51e041c8932ddac10595d4301a1a Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Tue, 11 Feb 2014 21:17:19 +0100 Subject: [PATCH] yep, dryrun option has now a unittest, was hard to work out ... --- cdist/test/config/__init__.py | 17 +++++++++++++++++ .../config/fixtures/manifest/dryrun_manifest | 1 + .../config/fixtures/type/__dryrun_test/.keep | 0 .../fixtures/type/__dryrun_test/gencode-local | 3 +++ .../fixtures/type/__dryrun_test/gencode-remote | 3 +++ 5 files changed, 24 insertions(+) create mode 100644 cdist/test/config/fixtures/manifest/dryrun_manifest create mode 100644 cdist/test/config/fixtures/type/__dryrun_test/.keep create mode 100644 cdist/test/config/fixtures/type/__dryrun_test/gencode-local create mode 100644 cdist/test/config/fixtures/type/__dryrun_test/gencode-remote diff --git a/cdist/test/config/__init__.py b/cdist/test/config/__init__.py index 80a45d9b..70501c89 100644 --- a/cdist/test/config/__init__.py +++ b/cdist/test/config/__init__.py @@ -2,6 +2,7 @@ # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -137,6 +138,22 @@ class ConfigRunTestCase(test.CdistTestCase): with self.assertRaises(cdist.core.cdist_object.MissingObjectIdError): self.config.iterate_until_finished() + + def test_dryrun(self): + """Test if the dryrun option is working like expected""" + drylocal = cdist.exec.local.Local( + target_host=self.target_host, + base_path=self.local_dir, + #exec_path can not derivated from sys.argv in case of unittest ... + exec_path=os.path.abspath(os.path.join(my_dir,'../../../scripts/cdist')), + initial_manifest=os.path.join(fixtures, 'manifest/dryrun_manifest'), + add_conf_dirs=[ fixtures ] ) + + dryrun = cdist.config.Config(drylocal, self.remote, dry_run=True) + dryrun.run() + # if we are here, dryrun works like expected + + # Currently the resolving code will simply detect that this object does # not exist. It should probably check if the type is a singleton as well # - but maybe only in the emulator - to be discussed. diff --git a/cdist/test/config/fixtures/manifest/dryrun_manifest b/cdist/test/config/fixtures/manifest/dryrun_manifest new file mode 100644 index 00000000..53bb9aa5 --- /dev/null +++ b/cdist/test/config/fixtures/manifest/dryrun_manifest @@ -0,0 +1 @@ +__dryrun_test testit diff --git a/cdist/test/config/fixtures/type/__dryrun_test/.keep b/cdist/test/config/fixtures/type/__dryrun_test/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__dryrun_test/gencode-local b/cdist/test/config/fixtures/type/__dryrun_test/gencode-local new file mode 100644 index 00000000..ccd584bd --- /dev/null +++ b/cdist/test/config/fixtures/type/__dryrun_test/gencode-local @@ -0,0 +1,3 @@ +# this type is only for testing the dryrun feature, it does nothing usefull +echo 'echo "This gencode-local script should never be executed >&2"' +echo 'exit 1' diff --git a/cdist/test/config/fixtures/type/__dryrun_test/gencode-remote b/cdist/test/config/fixtures/type/__dryrun_test/gencode-remote new file mode 100644 index 00000000..e57e4e27 --- /dev/null +++ b/cdist/test/config/fixtures/type/__dryrun_test/gencode-remote @@ -0,0 +1,3 @@ +# this type is only for testing the dryrun feature, it does nothing usefull +echo 'echo "this gencode-remote script should never be executed >&2"' +echo 'exit 1'