summaryrefslogtreecommitdiff
path: root/test/integration/targets/template
diff options
context:
space:
mode:
authorJulien Champseix <birdypme@users.noreply.github.com>2018-07-25 22:10:40 +0200
committerToshio Kuratomi <a.badger@gmail.com>2018-07-25 13:10:40 -0700
commit19dc267e4cae675831015b2c224d7d961398cc58 (patch)
tree9127a3c00bb3bda82ffa065393164141a03917bb /test/integration/targets/template
parent5b4a7cc283422525001b3b9e1d86d8fb29d3aec4 (diff)
downloadansible-19dc267e4cae675831015b2c224d7d961398cc58.tar.gz
Allow specifying the output encoding in the template module (#42171)
Allow specifying the source and destination files' encodings in the template module * Added output_encoding to the template module, default to utf-8 * Added documentation for the new variables * Leveraged the encoding argument on to_text() and to_bytes() to keep the implementation as simple as possible * Added integration tests with files in utf-8 and windows-1252 encodings, testing all combinations * fix bad smell test by excluding windows-1252 files from the utf8 checks * fix bad smell test by excluding valid files from the smart quote test
Diffstat (limited to 'test/integration/targets/template')
-rw-r--r--test/integration/targets/template/files/encoding_1252_utf-8.expected1
-rw-r--r--test/integration/targets/template/files/encoding_1252_windows-1252.expected1
-rw-r--r--test/integration/targets/template/tasks/main.yml23
-rw-r--r--test/integration/targets/template/templates/encoding_1252.j21
4 files changed, 26 insertions, 0 deletions
diff --git a/test/integration/targets/template/files/encoding_1252_utf-8.expected b/test/integration/targets/template/files/encoding_1252_utf-8.expected
new file mode 100644
index 0000000000..0d3cc35251
--- /dev/null
+++ b/test/integration/targets/template/files/encoding_1252_utf-8.expected
@@ -0,0 +1 @@
+windows-1252 Special Characters: €‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
diff --git a/test/integration/targets/template/files/encoding_1252_windows-1252.expected b/test/integration/targets/template/files/encoding_1252_windows-1252.expected
new file mode 100644
index 0000000000..7fb94a7b06
--- /dev/null
+++ b/test/integration/targets/template/files/encoding_1252_windows-1252.expected
@@ -0,0 +1 @@
+windows-1252 Special Characters:
diff --git a/test/integration/targets/template/tasks/main.yml b/test/integration/targets/template/tasks/main.yml
index 7e34852afa..87e2e7d16f 100644
--- a/test/integration/targets/template/tasks/main.yml
+++ b/test/integration/targets/template/tasks/main.yml
@@ -619,5 +619,28 @@
- 'template_results.mode == "0547"'
- 'stat_results.stat["mode"] == "0547"'
+# Test output_encoding
+- name: Prepare the list of encodings we want to check, including empty string for defaults
+ set_fact:
+ template_encoding_1252_encodings: ['', 'utf-8', 'windows-1252']
+
+- name: Copy known good encoding_1252_*.expected into place
+ copy:
+ src: 'encoding_1252_{{ item | default("utf-8", true) }}.expected'
+ dest: '{{ output_dir }}/encoding_1252_{{ item }}.expected'
+ loop: '{{ template_encoding_1252_encodings }}'
+
+- name: Generate the encoding_1252_* files from templates using various encoding combinations
+ template:
+ src: 'encoding_1252.j2'
+ dest: '{{ output_dir }}/encoding_1252_{{ item }}.txt'
+ output_encoding: '{{ item }}'
+ loop: '{{ template_encoding_1252_encodings }}'
+
+- name: Compare the encoding_1252_* templated files to known good
+ command: diff -u {{ output_dir }}/encoding_1252_{{ item }}.expected {{ output_dir }}/encoding_1252_{{ item }}.txt
+ register: encoding_1252_diff_result
+ loop: '{{ template_encoding_1252_encodings }}'
+
# aliases file requires root for template tests so this should be safe
- include: backup_test.yml
diff --git a/test/integration/targets/template/templates/encoding_1252.j2 b/test/integration/targets/template/templates/encoding_1252.j2
new file mode 100644
index 0000000000..0d3cc35251
--- /dev/null
+++ b/test/integration/targets/template/templates/encoding_1252.j2
@@ -0,0 +1 @@
+windows-1252 Special Characters: €‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ