Skip to content

Commit

Permalink
test ah_namespace fix
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
  • Loading branch information
Akasurde committed Sep 17, 2024
1 parent b69da70 commit ab196a7
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 3 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,18 @@ jobs:
working-directory: galaxy_ng
run: python3 dev/oci_env_integration/actions/ci.py

- name: Run integration tests
run: ansible-test integration ah_namespace
- name: Create integration config
working-directory: /home/runner/collections/ansible_collections/ansible/hub/tests/integration/
run: |
echo "ah_host: 'http://localhost:55001/'" > integration_config.yml
echo "ah_username: admin" >> integration_config.yml
echo "ah_password: admin" >> integration_config.yml
echo "ah_verify_ssl: false" >> integration_config.yml
- name: Run integration test - ah_namespace
run: ansible-test integration ah_namespace
working-directory: /home/runner/collections/ansible_collections/ansible/hub

- name: Run integration test - ah_build
run: ansible-test integration ah_build
working-directory: /home/runner/collections/ansible_collections/ansible/hub
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ansible Collection - sample.sample

Documentation for the collection.
17 changes: 17 additions & 0 deletions tests/integration/targets/ah_build/files/sample/sample/galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace: sample
name: sample
version: 1.0.0
readme: README.md
authors:
- your name <example@domain.com>
description: your collection description
license:
- GPL-2.0-or-later
license_file: ''
tags: []
dependencies: {}
repository: http://example.com/repository
documentation: http://docs.example.com
homepage: http://example.com
issues: http://example.com/issue/tracker
build_ignore: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Collections Plugins Directory

This directory can be used to ship various plugins inside an Ansible collection. Each plugin is placed in a folder that
is named after the type of plugin it is in. It can also include the `module_utils` and `modules` directory that
would contain module utils and modules respectively.

Here is an example directory of the majority of plugins currently supported by Ansible:

```
└── plugins
├── action
├── become
├── cache
├── callback
├── cliconf
├── connection
├── filter
├── httpapi
├── inventory
├── lookup
├── module_utils
├── modules
├── netconf
├── shell
├── strategy
├── terminal
├── test
└── vars
```

A full list of plugin types can be found at [Working With Plugins](https://docs.ansible.com/ansible-core/2.16/plugins/plugins.html).
62 changes: 62 additions & 0 deletions tests/integration/targets/ah_build/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
- name: ah_build integration tests
block:
- name: Generate a test_id for the test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}"
when: test_id is not defined

- name: Define variables
set_fact:
namespace: "sample"
company: "my_company_{{ test_id }}"
collection_name: "sample"
build_path: "{{ playbook_dir }}/targets/ah_build/files"

- name: Build Ansible Collection from the directory
ansible.hub.ah_build:
path: "{{ build_path }}/sample/sample"
output_path: "{{ build_path }}/"
register: r

- name: Check if the file exists
ansible.builtin.stat:
path: "{{ build_path }}/sample-sample-1.0.0.tar.gz"
register: build_stat

- name: Check if the build is successful
assert:
that:
- r.changed
- build_stat.stat.exists

- name: Build Ansible Collection from the directory again
ansible.hub.ah_build:
path: "{{ build_path }}/sample/sample"
output_path: "{{ build_path }}/"
register: r
ignore_errors: yes

- name: Check if re-building the collection without force fails
assert:
that:
- r.failed
- "'ERROR' in r.msg"

- name: Build Ansible Collection from the directory again
ansible.hub.ah_build:
path: "{{ build_path }}/sample/sample"
output_path: "{{ build_path }}/"
force: true
register: r

- name: Check if re-building the collection with force works
assert:
that:
- r.changed
always:
- name: Remove built collection
ansible.builtin.file:
path: "{{ build_path }}/sample-sample-1.0.0.tar.gz"
state: absent
ignore_errors: true
7 changes: 6 additions & 1 deletion tests/integration/targets/ah_namespace/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
---
- name: ah_namespace integration tests
module_defaults:
group/ansible.hub.hub:
ah_host: "{{ ah_host }}"
ah_username: "{{ ah_username }}"
ah_password: "{{ ah_password }}"
validate_certs: "{{ ah_verify_ssl }}"
block:
- name: Generate a test_id for the test
set_fact:
Expand Down Expand Up @@ -45,4 +51,3 @@
name: "{{ namespace }}"
state: absent
ignore_errors: true

0 comments on commit ab196a7

Please sign in to comment.