From 6f238e924c4fbbf08faeb8e75ae2308c5c203d58 Mon Sep 17 00:00:00 2001 From: Justin Findlay Date: Tue, 30 Jun 2015 14:26:59 -0600 Subject: [PATCH] integration test file.managed sources --- tests/integration/states/file.py | 64 +++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/tests/integration/states/file.py b/tests/integration/states/file.py index e01cde7cb3..c6dd5c3365 100644 --- a/tests/integration/states/file.py +++ b/tests/integration/states/file.py @@ -12,6 +12,7 @@ import pwd import shutil import stat import tempfile +import textwrap import filecmp # Import Salt Testing libs @@ -21,13 +22,15 @@ from salttesting.helpers import ( ensure_in_syspath, with_system_user_and_group ) -ensure_in_syspath('../../') +ensure_in_syspath('../../') # Import salt libs import integration import salt.utils +STATE_DIR = os.path.join(integration.FILES, 'file', 'base') + class FileTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn): ''' @@ -237,6 +240,65 @@ class FileTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn): changes = ret.values()[0]['changes'] self.assertEqual('', changes['diff']) + def test_managed_contents(self): + ''' + test file.managed with contents that is a boolean, string, integer, + float, list, and dictionary + ''' + state_name = 'file-FileTest-test_managed_contents' + state_filename = state_name + '.sls' + state_file = os.path.join(STATE_DIR, state_filename) + + managed_files = {} + state_keys = {} + for typ in ('bool', 'str', 'int', 'float', 'list', 'dict'): + managed_files[typ] = tempfile.mkstemp()[1] + state_keys[typ] = 'file_|-{0} file_|-{1}_|-managed'.format(typ, managed_files[typ]) + try: + salt.utils.fopen(state_file, 'w').write(textwrap.dedent('''\ + bool file: + file.managed: + - name: {bool} + - contents: True + + str file: + file.managed: + - name: {str} + - contents: Salt was here. + + int file: + file.managed: + - name: {int} + - contents: 340282366920938463463374607431768211456 + + float file: + file.managed: + - name: {float} + - contents: 1.7518e-45 # gravitational coupling constant + + list file: + file.managed: + - name: {list} + - contents: [1, 1, 2, 3, 5, 8, 13] + + dict file: + file.managed: + - name: {dict} + - contents: + C: charge + P: parity + T: time + '''.format(**managed_files))) + + ret = self.run_function('state.sls', [state_name]) + for typ in state_keys: + self.assertTrue(ret[state_keys[typ]]['result']) + self.assertIn('diff', ret[state_keys[typ]]['changes']) + finally: + os.remove(state_file) + for typ in managed_files: + os.remove(managed_files[typ]) + def test_directory(self): ''' file.directory