summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2024-06-20 19:50:27 +0200
committerGitHub <noreply@github.com>2024-06-20 19:50:27 +0200
commitc93af4e148a0f04aef36d78e852ede057a02e701 (patch)
treea3f84a833854d6265fe5d73efbdee966bd500bdb /test
parentget_url: Verify checksum using tmpsrc, not dest (#64092) (diff)
downloadansible-c93af4e148a0f04aef36d78e852ede057a02e701.tar.xz
ansible-c93af4e148a0f04aef36d78e852ede057a02e701.zip
unarchive: handle content and size differences (#83454)
Consider content differs and size differs while unarchiving the same tar.gz file Fixes: #29610 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Diffstat (limited to 'test')
-rw-r--r--test/integration/targets/unarchive/files/content_differs.tar.gzbin0 -> 156 bytes
-rw-r--r--test/integration/targets/unarchive/files/content_differs_2.tar.gzbin0 -> 158 bytes
-rw-r--r--test/integration/targets/unarchive/files/size_differs.tar.gzbin0 -> 153 bytes
-rw-r--r--test/integration/targets/unarchive/files/size_differs_2.tar.gzbin0 -> 182 bytes
-rw-r--r--test/integration/targets/unarchive/tasks/main.yml2
-rw-r--r--test/integration/targets/unarchive/tasks/test_tar_gz_content_differs.yml56
-rw-r--r--test/integration/targets/unarchive/tasks/test_tar_gz_size_differs.yml52
7 files changed, 110 insertions, 0 deletions
diff --git a/test/integration/targets/unarchive/files/content_differs.tar.gz b/test/integration/targets/unarchive/files/content_differs.tar.gz
new file mode 100644
index 0000000000..86d0891be5
--- /dev/null
+++ b/test/integration/targets/unarchive/files/content_differs.tar.gz
Binary files differ
diff --git a/test/integration/targets/unarchive/files/content_differs_2.tar.gz b/test/integration/targets/unarchive/files/content_differs_2.tar.gz
new file mode 100644
index 0000000000..d048e50f8c
--- /dev/null
+++ b/test/integration/targets/unarchive/files/content_differs_2.tar.gz
Binary files differ
diff --git a/test/integration/targets/unarchive/files/size_differs.tar.gz b/test/integration/targets/unarchive/files/size_differs.tar.gz
new file mode 100644
index 0000000000..7f76808dc7
--- /dev/null
+++ b/test/integration/targets/unarchive/files/size_differs.tar.gz
Binary files differ
diff --git a/test/integration/targets/unarchive/files/size_differs_2.tar.gz b/test/integration/targets/unarchive/files/size_differs_2.tar.gz
new file mode 100644
index 0000000000..0d53561b84
--- /dev/null
+++ b/test/integration/targets/unarchive/files/size_differs_2.tar.gz
Binary files differ
diff --git a/test/integration/targets/unarchive/tasks/main.yml b/test/integration/targets/unarchive/tasks/main.yml
index b07c2fe7fb..278642a106 100644
--- a/test/integration/targets/unarchive/tasks/main.yml
+++ b/test/integration/targets/unarchive/tasks/main.yml
@@ -5,6 +5,8 @@
- import_tasks: test_tar_gz_creates.yml
- import_tasks: test_tar_gz_owner_group.yml
- import_tasks: test_tar_gz_keep_newer.yml
+- import_tasks: test_tar_gz_size_differs.yml
+- import_tasks: test_tar_gz_content_differs.yml
- import_tasks: test_tar_zst.yml
- import_tasks: test_zip.yml
- import_tasks: test_exclude.yml
diff --git a/test/integration/targets/unarchive/tasks/test_tar_gz_content_differs.yml b/test/integration/targets/unarchive/tasks/test_tar_gz_content_differs.yml
new file mode 100644
index 0000000000..79a0be2398
--- /dev/null
+++ b/test/integration/targets/unarchive/tasks/test_tar_gz_content_differs.yml
@@ -0,0 +1,56 @@
+- set_fact:
+ dest: '{{remote_tmp_dir}}/test-unarchive-tar-gz-content-differs'
+
+- name: create our tar.gz unarchive destination
+ file:
+ path: "{{ dest }}"
+ state: directory
+
+- name: unarchive a tar.gz file
+ unarchive:
+ src: 'content_differs.tar.gz'
+ dest: '{{ dest }}'
+ remote_src: no
+ register: unarchive_content_differs_01
+
+- name: verify that the task was marked as changed
+ assert:
+ that:
+ - unarchive_content_differs_01.changed
+
+- name: checksum the file after first unarchive
+ stat:
+ path: '{{ dest }}/hello.txt'
+ checksum_algorithm: sha256
+ get_checksum: yes
+ register: first_unarchive_content
+
+- name: unarchive a tar.gz file with same name, size but different content
+ unarchive:
+ src: 'content_differs_2.tar.gz'
+ dest: '{{ dest }}'
+ remote_src: no
+ register: unarchive_content_differs_01
+
+- name: verify that the task was marked as changed
+ assert:
+ that:
+ - unarchive_content_differs_01.changed
+
+- name: checksum the file after second unarchive
+ stat:
+ path: '{{ dest }}/hello.txt'
+ checksum_algorithm: sha256
+ get_checksum: yes
+ register: second_unarchive_content
+
+- name: verify that unarchive extracted file with new content
+ assert:
+ that:
+ - first_unarchive_content.stat.checksum != second_unarchive_content.stat.checksum
+ - first_unarchive_content.stat.size == second_unarchive_content.stat.size
+
+- name: remove our tar.gz unarchive destination
+ file:
+ path: '{{ dest }}'
+ state: absent
diff --git a/test/integration/targets/unarchive/tasks/test_tar_gz_size_differs.yml b/test/integration/targets/unarchive/tasks/test_tar_gz_size_differs.yml
new file mode 100644
index 0000000000..c4a0d2af80
--- /dev/null
+++ b/test/integration/targets/unarchive/tasks/test_tar_gz_size_differs.yml
@@ -0,0 +1,52 @@
+- set_fact:
+ dest: '{{remote_tmp_dir}}/test-unarchive-tar-gz-size-differs'
+
+- name: create our tar.gz unarchive destination
+ file:
+ path: "{{ dest }}"
+ state: directory
+
+- name: unarchive a tar.gz file
+ unarchive:
+ src: 'size_differs.tar.gz'
+ dest: '{{ dest }}'
+ remote_src: no
+ register: unarchive_size_differs_01
+
+- name: verify that the task was marked as changed
+ assert:
+ that:
+ - unarchive_size_differs_01.changed
+
+- name: Check size after first unarchive
+ stat:
+ path: '{{ dest }}/hello.txt'
+ register: first_unarchive
+
+- name: unarchive a tar.gz file with same name but different size
+ unarchive:
+ src: 'size_differs_2.tar.gz'
+ dest: '{{ dest }}'
+ remote_src: no
+ register: unarchive_size_differs_02
+
+- name: verify that the task was marked as changed
+ assert:
+ that:
+ - unarchive_size_differs_02.changed
+
+- name: Check size after unarchive
+ stat:
+ path: '{{ dest }}/hello.txt'
+ register: second_unarchive
+
+- name: verify that unarchive extracted new sized file
+ assert:
+ that:
+ - first_unarchive.stat.size != second_unarchive.stat.size
+ - first_unarchive.stat.size < second_unarchive.stat.size
+
+- name: remove our tar.gz unarchive destination
+ file:
+ path: '{{ dest }}'
+ state: absent