generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
239 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v2 | ||
name: dep_up | ||
description: A Helm chart for molecule test | ||
type: application | ||
version: 0.1.0 | ||
appVersion: "default" | ||
dependencies: | ||
- name: test-chart | ||
repository: file://../test-chart | ||
version: "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
chart-test: | ||
myValue: helm update dependency test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
- name: copy chart | ||
copy: | ||
src: "{{ item }}" | ||
dest: /tmp | ||
loop: | ||
- test-chart | ||
- dep-up | ||
|
||
- name: "Test chart without dependencies block" | ||
block: | ||
- name: "Test chart without dependencies block" | ||
helm: | ||
binary_path: "{{ helm_binary }}" | ||
name: test | ||
chart_ref: "/tmp/test-chart" | ||
chart_version: "{{ chart_source_version | default(omit) }}" | ||
namespace: "{{ helm_namespace }}" | ||
create_namespace: yes | ||
register: release | ||
|
||
- debug: var=release | ||
|
||
- name: "Check if the subchart exist in chart" | ||
stat: | ||
path: "/tmp/test-chart/Chart.lock" | ||
register: stat_result | ||
|
||
- assert: | ||
that: | ||
- not stat_result.stat.exists | ||
success_msg: "There is no Subchart pulled" | ||
fail_msg: "subchart exist in the charts directory" | ||
|
||
- name: "Test chart with dependencies block" | ||
block: | ||
- name: "Test chart with dependencies block" | ||
helm: | ||
binary_path: "{{ helm_binary }}" | ||
name: test | ||
chart_ref: "/tmp/dep-up" | ||
chart_version: "{{ chart_source_version | default(omit) }}" | ||
namespace: "{{ helm_namespace }}" | ||
create_namespace: yes | ||
register: release | ||
|
||
- name: "Check if the subchart exist in chart" | ||
stat: | ||
path: "/tmp/dep-up/Chart.lock" | ||
register: stat_result | ||
|
||
- assert: | ||
that: | ||
- stat_result.stat.exists | ||
success_msg: "subchart exist in the chart directory" | ||
fail_msg: "subchart not exist in the charts directory" | ||
|
||
# Test The update dependency with chart_repo_url | ||
- name: "Test chart without dependencies block and chart_repo_url defined" | ||
block: | ||
- name: "Test chart without dependencies block and chart_repo_url defined" | ||
helm: | ||
binary_path: "{{ helm_binary }}" | ||
name: test | ||
chart_ref: "ingress-nginx" | ||
chart_repo_url: https://kubernetes.github.io/ingress-nginx | ||
chart_version: "{{ chart_source_version | default(omit) }}" | ||
namespace: "{{ helm_namespace }}" | ||
create_namespace: yes | ||
register: release | ||
|
||
- assert: | ||
that: | ||
- "'--dependency-update' not in release.command" | ||
- "'upgrade' in release.command" | ||
success_msg: "Command does not contains '--dependency-update' options" | ||
fail_msg: "Command contains '--dependency-update' options" | ||
|
||
- name: "Test chart with dependencies block and chart_repo_url defined and replace True" | ||
block: | ||
- name: "Test chart with dependencies block and chart_repo_url defined and replace True" | ||
helm: | ||
binary_path: "{{ helm_binary }}" | ||
name: test1 | ||
chart_ref: "dep_up" | ||
chart_repo_url: http://repo:8080/charts | ||
chart_version: "{{ chart_source_version | default(omit) }}" | ||
namespace: "{{ helm_namespace }}" | ||
create_namespace: yes | ||
replace: true | ||
register: release | ||
- debug: var=release | ||
- assert: | ||
that: | ||
- "'--dependency-update' in release.command" | ||
- "'install' in release.command" | ||
success_msg: "Command contains '--dependency-update' options with helm install command" | ||
fail_msg: "Command not contains '--dependency-update' with helm install command" | ||
|
||
- name: "Test chart with dependencies block and chart_repo_url defined and replace False fails" | ||
block: | ||
- name: "Test chart with dependencies block and chart_repo_url defined and replace False fails" | ||
helm: | ||
binary_path: "{{ helm_binary }}" | ||
name: test2 | ||
chart_ref: "dep_up" | ||
chart_repo_url: http://repo:8080/charts | ||
chart_version: "{{ chart_source_version | default(omit) }}" | ||
namespace: "{{ helm_namespace }}" | ||
create_namespace: yes | ||
replace: false | ||
register: release | ||
ignore_errors: true | ||
|
||
- assert: | ||
that: | ||
- release.failed | ||
- release.msg == "'--dependency-update' hasn't been supported yet with 'helm upgrade'. Please use 'helm install' instead by adding 'replace' option" | ||
success_msg: "Command build fail when adding '--dependency-update' with the helm upgrade command" | ||
|
||
- name: Remove helm namespace | ||
k8s: | ||
api_version: v1 | ||
kind: Namespace | ||
name: "{{ helm_namespace }}" | ||
state: absent | ||
wait: true | ||
wait_timeout: 180 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright: (c) 2020, Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import absolute_import, division, print_function | ||
from unittest.mock import MagicMock, patch | ||
|
||
__metaclass__ = type | ||
|
||
from ansible_collections.kubernetes.core.plugins.modules.helm import ( | ||
run_dep_update | ||
) | ||
|
||
|
||
class MockedModule: | ||
def __init__(self): | ||
self.params = { | ||
"api_key": None, | ||
"ca_cert": None, | ||
"host": None, | ||
"kube_context": None, | ||
"kubeconfig": None, | ||
"release_namespace": None, | ||
"validate_certs": None, | ||
} | ||
|
||
self.r = {} | ||
|
||
def run_command(self, command, environ_update=None): | ||
self.r = {"command": command, "environ_update": environ_update} | ||
return 0, "", "" | ||
|
||
|
||
def chart_info(): | ||
return { | ||
'apiVersion': 'v2', | ||
'appVersion': 'default', | ||
'dependencies': [{'name': 'test-chart', 'repository': 'file://../test-chart', 'version': '0.1.0'}], | ||
'description': 'A Helm chart for molecule test', | ||
'name': 'dep_up', | ||
'type': 'application', | ||
'version': '0.1.0' | ||
} | ||
|
||
|
||
def test_dependency_update_naked(): | ||
module = MockedModule() | ||
module.params = {} | ||
common_cmd = "helm" | ||
chart_ref = "/tmp/path/chart" | ||
run_dep_update(module, common_cmd, chart_ref) | ||
assert module.r["command"] == "helm dependency update /tmp/path/chart" | ||
assert module.r["environ_update"] == {} |