From 5ae3ea0fba31a72700ced5175456b8cc01af7685 Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Wed, 6 Dec 2023 17:03:39 +0000 Subject: [PATCH] Add molecule test for upload_helm_chart 'copy' method This patch also extends the molecule test to cover the case where a new version of a chart is uploaded which should result in a file being removed from the destination. --- .../charts/{foo => foo-v1}/.gitkeep | 0 .../chart/.gitkeep => charts/foo-v1/file} | 0 .../upload-helm-chart/charts/foo-v2/.gitkeep | 0 molecule/upload-helm-chart/converge.yml | 2 ++ .../roles/test-role/files/chart-v1/.gitkeep | 0 .../roles/test-role/files/chart-v1/file | 0 .../roles/test-role/files/chart-v2/.gitkeep | 0 .../roles/test-role/meta/main.yml | 11 ++++--- molecule/upload-helm-chart/side_effect.yml | 21 +++++++++++++ molecule/upload-helm-chart/verify.yml | 30 +++++++++++++++++++ 10 files changed, 60 insertions(+), 4 deletions(-) rename molecule/upload-helm-chart/charts/{foo => foo-v1}/.gitkeep (100%) rename molecule/upload-helm-chart/{roles/test-role/files/chart/.gitkeep => charts/foo-v1/file} (100%) create mode 100644 molecule/upload-helm-chart/charts/foo-v2/.gitkeep create mode 100644 molecule/upload-helm-chart/roles/test-role/files/chart-v1/.gitkeep create mode 100644 molecule/upload-helm-chart/roles/test-role/files/chart-v1/file create mode 100644 molecule/upload-helm-chart/roles/test-role/files/chart-v2/.gitkeep create mode 100644 molecule/upload-helm-chart/side_effect.yml create mode 100644 molecule/upload-helm-chart/verify.yml diff --git a/molecule/upload-helm-chart/charts/foo/.gitkeep b/molecule/upload-helm-chart/charts/foo-v1/.gitkeep similarity index 100% rename from molecule/upload-helm-chart/charts/foo/.gitkeep rename to molecule/upload-helm-chart/charts/foo-v1/.gitkeep diff --git a/molecule/upload-helm-chart/roles/test-role/files/chart/.gitkeep b/molecule/upload-helm-chart/charts/foo-v1/file similarity index 100% rename from molecule/upload-helm-chart/roles/test-role/files/chart/.gitkeep rename to molecule/upload-helm-chart/charts/foo-v1/file diff --git a/molecule/upload-helm-chart/charts/foo-v2/.gitkeep b/molecule/upload-helm-chart/charts/foo-v2/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/molecule/upload-helm-chart/converge.yml b/molecule/upload-helm-chart/converge.yml index 6d4b6965..47ac23f4 100644 --- a/molecule/upload-helm-chart/converge.yml +++ b/molecule/upload-helm-chart/converge.yml @@ -17,3 +17,5 @@ become: true roles: - role: test-role + vars: + test_relative_path : "chart-v1/" diff --git a/molecule/upload-helm-chart/roles/test-role/files/chart-v1/.gitkeep b/molecule/upload-helm-chart/roles/test-role/files/chart-v1/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/molecule/upload-helm-chart/roles/test-role/files/chart-v1/file b/molecule/upload-helm-chart/roles/test-role/files/chart-v1/file new file mode 100644 index 00000000..e69de29b diff --git a/molecule/upload-helm-chart/roles/test-role/files/chart-v2/.gitkeep b/molecule/upload-helm-chart/roles/test-role/files/chart-v2/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/molecule/upload-helm-chart/roles/test-role/meta/main.yml b/molecule/upload-helm-chart/roles/test-role/meta/main.yml index 2e31e7ff..e0e91022 100644 --- a/molecule/upload-helm-chart/roles/test-role/meta/main.yml +++ b/molecule/upload-helm-chart/roles/test-role/meta/main.yml @@ -1,9 +1,12 @@ dependencies: - role: vexxhost.kubernetes.upload_helm_chart vars: - upload_helm_chart_src: "./files/chart/" - upload_helm_chart_dest: /usr/local/src/chart-1 + # with rsync + upload_helm_chart_src: "{{ test_relative_path }}" + upload_helm_chart_dest: /usr/local/src/chart-one - role: vexxhost.kubernetes.upload_helm_chart vars: - upload_helm_chart_src: "../../charts/foo/" - upload_helm_chart_dest: /usr/local/src/chart-2 + # with multi_copy + upload_helm_chart_src: "{{ test_relative_path }}" + upload_helm_chart_dest: /usr/local/src/chart-two + upload_helm_chart_method: copy diff --git a/molecule/upload-helm-chart/side_effect.yml b/molecule/upload-helm-chart/side_effect.yml new file mode 100644 index 00000000..61205f5e --- /dev/null +++ b/molecule/upload-helm-chart/side_effect.yml @@ -0,0 +1,21 @@ +# Copyright (c) 2023 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Side effect + hosts: all + become: true + roles: + - role: test-role + vars: + test_relative_path: "chart-v2/" diff --git a/molecule/upload-helm-chart/verify.yml b/molecule/upload-helm-chart/verify.yml new file mode 100644 index 00000000..e36dfa4a --- /dev/null +++ b/molecule/upload-helm-chart/verify.yml @@ -0,0 +1,30 @@ +- name: Verify + hosts: all + become: true + tasks: + - name: Stat file 1 + ansible.builtin.stat: + path: /usr/local/src/chart-one/.gitkeep + register: stat_1 + + - name: Stat file 2 + ansible.builtin.stat: + path: /usr/local/src/chart-two/.gitkeep + register: stat_2 + + - name: Stat removed file 1 + ansible.builtin.stat: + path: /usr/local/src/chart-one/file + register: stat_r1 + + - name: Stat removed file 2 + ansible.builtin.stat: + path: /usr/local/src/chart-two/file + register: stat_r2 + + - ansible.builtin.assert: + that: + - stat_1.stat.exists + - stat_2.stat.exists + - not stat_r1.stat.exists + - not stat_r2.stat.exists