From b2e59038530ecbdf1b3b0b1435025d4e752b5a72 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 20 Feb 2014 15:33:27 -0500 Subject: [PATCH] Add some missing files for filters and ignore_errors tests --- .../roles/test_filters/files/foo.txt | 73 +++++++++++++++++++ .../roles/test_filters/meta/main.yml | 3 + .../roles/test_filters/tasks/main.yml | 40 ++++++++++ .../roles/test_filters/templates/foo.j2 | 60 +++++++++++++++ .../roles/test_filters/vars/main.yml | 6 ++ .../roles/test_ignore_errors/meta/main.yml | 3 + 6 files changed, 185 insertions(+) create mode 100644 tests_new/integration/roles/test_filters/files/foo.txt create mode 100644 tests_new/integration/roles/test_filters/meta/main.yml create mode 100644 tests_new/integration/roles/test_filters/tasks/main.yml create mode 100644 tests_new/integration/roles/test_filters/templates/foo.j2 create mode 100644 tests_new/integration/roles/test_filters/vars/main.yml create mode 100644 tests_new/integration/roles/test_ignore_errors/meta/main.yml diff --git a/tests_new/integration/roles/test_filters/files/foo.txt b/tests_new/integration/roles/test_filters/files/foo.txt new file mode 100644 index 00000000000..aa9aea76868 --- /dev/null +++ b/tests_new/integration/roles/test_filters/files/foo.txt @@ -0,0 +1,73 @@ +This is a test of various filter plugins found in Ansible (ex: core.py), and +not so much a test of the core filters in Jinja2. + +Dumping a nested structure to JSON + +[ + "this is a list element", + { + "this": "is a hash element in a list", + "warp": 9, + "where": "endor" + } +] + +Dumping the same structure to YAML + +- this is a list element +- this: is a hash element in a list + warp: 9 + where: endor + + +Dumping the same structure to JSON, but don't pretty print + +["this is a list element", {"this": "is a hash element in a list", "where": "endor", "warp": 9}] + +Dumping the same structure to YAML, but don't pretty print + +- this is a list element +- {this: is a hash element in a list, warp: 9, where: endor} + + +From a recorded task, the changed, failed, success, and skipped +filters are shortcuts to ask if those tasks produced changes, failed, +succeeded, or skipped (as one might guess). + +Changed = True +Failed = False +Success = True +Skipped = False + +The mandatory filter fails if a variable is not defined and returns the value. +To avoid breaking this test, this variable is already defined. + +a = 1 + +There are various casts available + +int = 1 +bool = True + +String quoting + +quoted = quoted + +The fileglob module returns the list of things matching a pattern. + +fileglob = [] + +There are also various string operations that work on paths. These do not require +files to exist and are passthrus to the python os.path functions + +'~/foo' with expanduser = /root/foo +/etc/motd with basename = motd +/etc/motd with dirname = /etc + +TODO: realpath follows symlinks. There isn't a test for this just now. + +TODO: add tests for set theory operations like union + +TODO: add tests for regex, match, and search + + diff --git a/tests_new/integration/roles/test_filters/meta/main.yml b/tests_new/integration/roles/test_filters/meta/main.yml new file mode 100644 index 00000000000..1050c23ce30 --- /dev/null +++ b/tests_new/integration/roles/test_filters/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/tests_new/integration/roles/test_filters/tasks/main.yml b/tests_new/integration/roles/test_filters/tasks/main.yml new file mode 100644 index 00000000000..985cbf83275 --- /dev/null +++ b/tests_new/integration/roles/test_filters/tasks/main.yml @@ -0,0 +1,40 @@ +# test code +# (c) 2014, Michael DeHaan + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +- name: a dummy task to test the changed and success filters + shell: echo hi + register: some_registered_var + +- debug: var=some_registered_var + +- name: fill in a basic template + template: src=foo.j2 dest={{output_dir}}/foo.templated mode=0644 + register: template_result + +- name: copy known good into place + copy: src=foo.txt dest={{output_dir}}/foo.txt + +- name: compare templated file to known good + shell: diff {{output_dir}}/foo.templated {{output_dir}}/foo.txt + register: diff_result + +- name: verify templated file matches known good + assert: + that: + - 'diff_result.stdout == ""' + diff --git a/tests_new/integration/roles/test_filters/templates/foo.j2 b/tests_new/integration/roles/test_filters/templates/foo.j2 new file mode 100644 index 00000000000..d1b2f163e5f --- /dev/null +++ b/tests_new/integration/roles/test_filters/templates/foo.j2 @@ -0,0 +1,60 @@ +This is a test of various filter plugins found in Ansible (ex: core.py), and +not so much a test of the core filters in Jinja2. + +Dumping a nested structure to JSON + +{{ some_structure | to_nice_json }} + +Dumping the same structure to YAML + +{{ some_structure | to_nice_yaml }} + +Dumping the same structure to JSON, but don't pretty print + +{{ some_structure | to_json }} + +Dumping the same structure to YAML, but don't pretty print + +{{ some_structure | to_yaml }} + +From a recorded task, the changed, failed, success, and skipped +filters are shortcuts to ask if those tasks produced changes, failed, +succeeded, or skipped (as one might guess). + +Changed = {{ some_registered_var | changed }} +Failed = {{ some_registered_var | failed }} +Success = {{ some_registered_var | success }} +Skipped = {{ some_registered_var | skipped }} + +The mandatory filter fails if a variable is not defined and returns the value. +To avoid breaking this test, this variable is already defined. + +a = {{ a | mandatory }} + +There are various casts available + +int = {{ a | int }} +bool = {{ 1 | bool }} + +String quoting + +quoted = {{ 'quoted' | quote }} + +The fileglob module returns the list of things matching a pattern. + +fileglob = {{ (output_dir + '/*') | fileglob }} + +There are also various string operations that work on paths. These do not require +files to exist and are passthrus to the python os.path functions + +'~/foo' with expanduser = {{ '~/foo' | expanduser }} +/etc/motd with basename = {{ '/etc/motd' | basename }} +/etc/motd with dirname = {{ '/etc/motd' | dirname }} + +TODO: realpath follows symlinks. There isn't a test for this just now. + +TODO: add tests for set theory operations like union + +TODO: add tests for regex, match, and search + + diff --git a/tests_new/integration/roles/test_filters/vars/main.yml b/tests_new/integration/roles/test_filters/vars/main.yml new file mode 100644 index 00000000000..133c2b613b8 --- /dev/null +++ b/tests_new/integration/roles/test_filters/vars/main.yml @@ -0,0 +1,6 @@ +some_structure: + - "this is a list element" + - + this: "is a hash element in a list" + warp: 9 + where: endor diff --git a/tests_new/integration/roles/test_ignore_errors/meta/main.yml b/tests_new/integration/roles/test_ignore_errors/meta/main.yml new file mode 100644 index 00000000000..1050c23ce30 --- /dev/null +++ b/tests_new/integration/roles/test_ignore_errors/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests +