summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/jinja2_native_types
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/jinja2_native_types')
-rw-r--r--test/integration/targets/jinja2_native_types/aliases2
-rw-r--r--test/integration/targets/jinja2_native_types/nested_undefined.yml23
-rwxr-xr-xtest/integration/targets/jinja2_native_types/runme.sh11
-rw-r--r--test/integration/targets/jinja2_native_types/runtests.yml40
-rw-r--r--test/integration/targets/jinja2_native_types/test_bool.yml53
-rw-r--r--test/integration/targets/jinja2_native_types/test_casting.yml31
-rw-r--r--test/integration/targets/jinja2_native_types/test_concatentation.yml88
-rw-r--r--test/integration/targets/jinja2_native_types/test_dunder.yml23
-rw-r--r--test/integration/targets/jinja2_native_types/test_hostvars.yml10
-rw-r--r--test/integration/targets/jinja2_native_types/test_none.yml11
-rw-r--r--test/integration/targets/jinja2_native_types/test_preserving_quotes.yml14
-rw-r--r--test/integration/targets/jinja2_native_types/test_template.yml27
-rw-r--r--test/integration/targets/jinja2_native_types/test_template_newlines.j24
-rw-r--r--test/integration/targets/jinja2_native_types/test_types.yml20
-rw-r--r--test/integration/targets/jinja2_native_types/test_vault.yml16
-rw-r--r--test/integration/targets/jinja2_native_types/test_vault_pass1
16 files changed, 374 insertions, 0 deletions
diff --git a/test/integration/targets/jinja2_native_types/aliases b/test/integration/targets/jinja2_native_types/aliases
new file mode 100644
index 0000000..1d28bdb
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group5
+context/controller
diff --git a/test/integration/targets/jinja2_native_types/nested_undefined.yml b/test/integration/targets/jinja2_native_types/nested_undefined.yml
new file mode 100644
index 0000000..b60a871
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/nested_undefined.yml
@@ -0,0 +1,23 @@
+- hosts: localhost
+ gather_facts: no
+ tasks:
+ - block:
+ - name: Test nested undefined var fails, single node
+ debug:
+ msg: "{{ [{ 'key': nested_and_undefined }] }}"
+ register: result
+ ignore_errors: yes
+
+ - assert:
+ that:
+ - "\"'nested_and_undefined' is undefined\" in result.msg"
+
+ - name: Test nested undefined var fails, multiple nodes
+ debug:
+ msg: "{{ [{ 'key': nested_and_undefined}] }} second_node"
+ register: result
+ ignore_errors: yes
+
+ - assert:
+ that:
+ - "\"'nested_and_undefined' is undefined\" in result.msg"
diff --git a/test/integration/targets/jinja2_native_types/runme.sh b/test/integration/targets/jinja2_native_types/runme.sh
new file mode 100755
index 0000000..a6c2bef
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/runme.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+set -eux
+
+export ANSIBLE_JINJA2_NATIVE=1
+ansible-playbook runtests.yml -v "$@"
+ansible-playbook --vault-password-file test_vault_pass test_vault.yml -v "$@"
+ansible-playbook test_hostvars.yml -v "$@"
+ansible-playbook nested_undefined.yml -v "$@"
+ansible-playbook test_preserving_quotes.yml -v "$@"
+unset ANSIBLE_JINJA2_NATIVE
diff --git a/test/integration/targets/jinja2_native_types/runtests.yml b/test/integration/targets/jinja2_native_types/runtests.yml
new file mode 100644
index 0000000..422ef57
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/runtests.yml
@@ -0,0 +1,40 @@
+- name: Test jinja2 native types
+ hosts: localhost
+ gather_facts: no
+ vars:
+ i_one: 1
+ i_two: 2
+ i_three: 3
+ s_one: "1"
+ s_two: "2"
+ s_three: "3"
+ dict_one:
+ foo: bar
+ baz: bang
+ dict_two:
+ bar: foo
+ foobar: barfoo
+ list_one:
+ - one
+ - two
+ list_two:
+ - three
+ - four
+ list_ints:
+ - 4
+ - 2
+ list_one_int:
+ - 1
+ b_true: True
+ b_false: False
+ s_true: "True"
+ s_false: "False"
+ yaml_none: ~
+ tasks:
+ - import_tasks: test_casting.yml
+ - import_tasks: test_concatentation.yml
+ - import_tasks: test_bool.yml
+ - import_tasks: test_dunder.yml
+ - import_tasks: test_types.yml
+ - import_tasks: test_none.yml
+ - import_tasks: test_template.yml
diff --git a/test/integration/targets/jinja2_native_types/test_bool.yml b/test/integration/targets/jinja2_native_types/test_bool.yml
new file mode 100644
index 0000000..f3b5e8c
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_bool.yml
@@ -0,0 +1,53 @@
+- name: test bool True
+ set_fact:
+ bool_var_true: "{{ b_true }}"
+
+- assert:
+ that:
+ - 'bool_var_true is sameas true'
+ - 'bool_var_true|type_debug == "bool"'
+
+- name: test bool False
+ set_fact:
+ bool_var_false: "{{ b_false }}"
+
+- assert:
+ that:
+ - 'bool_var_false is sameas false'
+ - 'bool_var_false|type_debug == "bool"'
+
+- name: test bool expr True
+ set_fact:
+ bool_var_expr_true: "{{ 1 == 1 }}"
+
+- assert:
+ that:
+ - 'bool_var_expr_true is sameas true'
+ - 'bool_var_expr_true|type_debug == "bool"'
+
+- name: test bool expr False
+ set_fact:
+ bool_var_expr_false: "{{ 2 + 2 == 5 }}"
+
+- assert:
+ that:
+ - 'bool_var_expr_false is sameas false'
+ - 'bool_var_expr_false|type_debug == "bool"'
+
+- name: test bool expr with None, True
+ set_fact:
+ bool_var_none_expr_true: "{{ None == None }}"
+
+- assert:
+ that:
+ - 'bool_var_none_expr_true is sameas true'
+ - 'bool_var_none_expr_true|type_debug == "bool"'
+
+- name: test bool expr with None, False
+ set_fact:
+ bool_var_none_expr_false: "{{ '' == None }}"
+
+- assert:
+ that:
+ - 'bool_var_none_expr_false is sameas false'
+ - 'bool_var_none_expr_false|type_debug == "bool"'
diff --git a/test/integration/targets/jinja2_native_types/test_casting.yml b/test/integration/targets/jinja2_native_types/test_casting.yml
new file mode 100644
index 0000000..5e9c76d
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_casting.yml
@@ -0,0 +1,31 @@
+- name: cast things to other things
+ set_fact:
+ int_to_str: "'{{ i_two }}'"
+ int_to_str2: "{{ i_two | string }}"
+ str_to_int: "{{ s_two|int }}"
+ dict_to_str: "'{{ dict_one }}'"
+ list_to_str: "'{{ list_one }}'"
+ int_to_bool: "{{ i_one|bool }}"
+ str_true_to_bool: "{{ s_true|bool }}"
+ str_false_to_bool: "{{ s_false|bool }}"
+ list_to_json_str: "{{ list_one | to_json }}"
+ list_to_yaml_str: "{{ list_one | to_yaml }}"
+
+- assert:
+ that:
+ - int_to_str == "'2'"
+ - 'int_to_str|type_debug in ["str", "unicode"]'
+ - 'int_to_str2 == "2"'
+ - 'int_to_str2|type_debug in ["NativeJinjaText"]'
+ - 'str_to_int == 2'
+ - 'str_to_int|type_debug == "int"'
+ - 'dict_to_str|type_debug in ["str", "unicode"]'
+ - 'list_to_str|type_debug in ["str", "unicode"]'
+ - 'int_to_bool is sameas true'
+ - 'int_to_bool|type_debug == "bool"'
+ - 'str_true_to_bool is sameas true'
+ - 'str_true_to_bool|type_debug == "bool"'
+ - 'str_false_to_bool is sameas false'
+ - 'str_false_to_bool|type_debug == "bool"'
+ - 'list_to_json_str|type_debug in ["NativeJinjaText"]'
+ - 'list_to_yaml_str|type_debug in ["NativeJinjaText"]'
diff --git a/test/integration/targets/jinja2_native_types/test_concatentation.yml b/test/integration/targets/jinja2_native_types/test_concatentation.yml
new file mode 100644
index 0000000..24a9038
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_concatentation.yml
@@ -0,0 +1,88 @@
+- name: add two ints
+ set_fact:
+ integer_sum: "{{ i_one + i_two }}"
+
+- assert:
+ that:
+ - 'integer_sum == 3'
+ - 'integer_sum|type_debug == "int"'
+
+- name: add casted string and int
+ set_fact:
+ integer_sum2: "{{ s_one|int + i_two }}"
+
+- assert:
+ that:
+ - 'integer_sum2 == 3'
+ - 'integer_sum2|type_debug == "int"'
+
+- name: concatenate int and string
+ set_fact:
+ string_sum: "'{{ [i_one, s_two]|join('') }}'"
+
+- assert:
+ that:
+ - string_sum == "'12'"
+ - 'string_sum|type_debug in ["str", "unicode"]'
+
+- name: add two lists
+ set_fact:
+ list_sum: "{{ list_one + list_two }}"
+
+- assert:
+ that:
+ - 'list_sum == ["one", "two", "three", "four"]'
+ - 'list_sum|type_debug == "list"'
+
+- name: add two lists, multi expression
+ set_fact:
+ list_sum_multi: "{{ list_one }} + {{ list_two }}"
+
+- assert:
+ that:
+ - 'list_sum_multi|type_debug in ["str", "unicode"]'
+
+- name: add two dicts
+ set_fact:
+ dict_sum: "{{ dict_one + dict_two }}"
+ ignore_errors: yes
+
+- assert:
+ that:
+ - 'dict_sum is undefined'
+
+- name: loop through list with strings
+ set_fact:
+ list_for_strings: "{% for x in list_one %}{{ x }}{% endfor %}"
+
+- assert:
+ that:
+ - 'list_for_strings == "onetwo"'
+ - 'list_for_strings|type_debug in ["str", "unicode"]'
+
+- name: loop through list with int
+ set_fact:
+ list_for_int: "{% for x in list_one_int %}{{ x }}{% endfor %}"
+
+- assert:
+ that:
+ - 'list_for_int == 1'
+ - 'list_for_int|type_debug == "int"'
+
+- name: loop through list with ints
+ set_fact:
+ list_for_ints: "{% for x in list_ints %}{{ x }}{% endfor %}"
+
+- assert:
+ that:
+ - 'list_for_ints == 42'
+ - 'list_for_ints|type_debug == "int"'
+
+- name: loop through list to create a new list
+ set_fact:
+ list_from_list: "[{% for x in list_ints %}{{ x }},{% endfor %}]"
+
+- assert:
+ that:
+ - 'list_from_list == [4, 2]'
+ - 'list_from_list|type_debug == "list"'
diff --git a/test/integration/targets/jinja2_native_types/test_dunder.yml b/test/integration/targets/jinja2_native_types/test_dunder.yml
new file mode 100644
index 0000000..df5ea92
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_dunder.yml
@@ -0,0 +1,23 @@
+- name: test variable dunder
+ set_fact:
+ var_dunder: "{{ b_true.__class__ }}"
+
+- assert:
+ that:
+ - 'var_dunder|type_debug == "type"'
+
+- name: test constant dunder
+ set_fact:
+ const_dunder: "{{ true.__class__ }}"
+
+- assert:
+ that:
+ - 'const_dunder|type_debug == "type"'
+
+- name: test constant dunder to string
+ set_fact:
+ const_dunder: "{{ true.__class__|string }}"
+
+- assert:
+ that:
+ - 'const_dunder|type_debug in ["str", "unicode", "NativeJinjaText"]'
diff --git a/test/integration/targets/jinja2_native_types/test_hostvars.yml b/test/integration/targets/jinja2_native_types/test_hostvars.yml
new file mode 100644
index 0000000..ef0047b
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_hostvars.yml
@@ -0,0 +1,10 @@
+- hosts: localhost
+ gather_facts: no
+ tasks:
+ - name: Print vars
+ debug:
+ var: vars
+
+ - name: Print hostvars
+ debug:
+ var: hostvars
diff --git a/test/integration/targets/jinja2_native_types/test_none.yml b/test/integration/targets/jinja2_native_types/test_none.yml
new file mode 100644
index 0000000..1d26154
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_none.yml
@@ -0,0 +1,11 @@
+- name: test none
+ set_fact:
+ none_var: "{{ yaml_none }}"
+ none_var_direct: "{{ None }}"
+
+- assert:
+ that:
+ - 'none_var is sameas none'
+ - 'none_var|type_debug == "NoneType"'
+ - 'none_var_direct is sameas none'
+ - 'none_var_direct|type_debug == "NoneType"'
diff --git a/test/integration/targets/jinja2_native_types/test_preserving_quotes.yml b/test/integration/targets/jinja2_native_types/test_preserving_quotes.yml
new file mode 100644
index 0000000..d6fea10
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_preserving_quotes.yml
@@ -0,0 +1,14 @@
+- hosts: localhost
+ gather_facts: false
+ tasks:
+ - assert:
+ that:
+ - quoted_str == '"hello"'
+ - empty_quoted_str == '""'
+ vars:
+ third_nested_lvl: '"hello"'
+ second_nested_lvl: "{{ third_nested_lvl }}"
+ first_nested_lvl: "{{ second_nested_lvl }}"
+ quoted_str: "{{ first_nested_lvl }}"
+ empty_quoted_str: "{{ empty_str }}"
+ empty_str: '""'
diff --git a/test/integration/targets/jinja2_native_types/test_template.yml b/test/integration/targets/jinja2_native_types/test_template.yml
new file mode 100644
index 0000000..0896ac1
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_template.yml
@@ -0,0 +1,27 @@
+- block:
+ - name: Template file with newlines
+ template:
+ src: test_template_newlines.j2
+ dest: test_template_newlines.res
+
+ - name: Dump template file
+ stat:
+ path: test_template_newlines.j2
+ get_checksum: yes
+ register: template_stat
+
+ - name: Dump result file
+ stat:
+ path: test_template_newlines.res
+ get_checksum: yes
+ register: result_stat
+
+ - name: Check that number of newlines from original template are preserved
+ assert:
+ that:
+ - template_stat.stat.checksum == result_stat.stat.checksum
+ always:
+ - name: Clean up
+ file:
+ path: test_template_newlines.res
+ state: absent
diff --git a/test/integration/targets/jinja2_native_types/test_template_newlines.j2 b/test/integration/targets/jinja2_native_types/test_template_newlines.j2
new file mode 100644
index 0000000..ca887ef
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_template_newlines.j2
@@ -0,0 +1,4 @@
+First line.
+
+
+
diff --git a/test/integration/targets/jinja2_native_types/test_types.yml b/test/integration/targets/jinja2_native_types/test_types.yml
new file mode 100644
index 0000000..f5659d4
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_types.yml
@@ -0,0 +1,20 @@
+- assert:
+ that:
+ - 'i_one|type_debug == "int"'
+ - 's_one|type_debug == "AnsibleUnicode"'
+ - 'dict_one|type_debug == "dict"'
+ - 'dict_one is mapping'
+ - 'list_one|type_debug == "list"'
+ - 'b_true|type_debug == "bool"'
+ - 's_true|type_debug == "AnsibleUnicode"'
+
+- set_fact:
+ a_list: "{{[i_one, s_two]}}"
+
+- assert:
+ that:
+ - 'a_list|type_debug == "list"'
+ - 'a_list[0] == 1'
+ - 'a_list[0]|type_debug == "int"'
+ - 'a_list[1] == "2"'
+ - 'a_list[1]|type_debug == "AnsibleUnicode"'
diff --git a/test/integration/targets/jinja2_native_types/test_vault.yml b/test/integration/targets/jinja2_native_types/test_vault.yml
new file mode 100644
index 0000000..2daa3c5
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_vault.yml
@@ -0,0 +1,16 @@
+- hosts: localhost
+ gather_facts: no
+ vars:
+ # ansible-vault encrypt_string root
+ # vault_password_file = test_vault_pass
+ vaulted_root_string: !vault |
+ $ANSIBLE_VAULT;1.1;AES256
+ 39333565666430306232343266346635373235626564396332323838613063646132653436303239
+ 3133363232306334393863343563366131373565616338380a666339383162333838653631663131
+ 36633637303862353435643930393664386365323164643831363332666435303436373365393162
+ 6535383134323539380a613663366631626534313837313565666665336164353362373431666366
+ 3464
+ tasks:
+ - name: make sure group root exists
+ group:
+ name: "{{ vaulted_root_string }}"
diff --git a/test/integration/targets/jinja2_native_types/test_vault_pass b/test/integration/targets/jinja2_native_types/test_vault_pass
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/test/integration/targets/jinja2_native_types/test_vault_pass
@@ -0,0 +1 @@
+test