Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ondra Machacek <omachace@redhat.com>
  • Loading branch information
machacekondra committed Feb 28, 2024
1 parent f977589 commit 3576a53
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Ansible Test
on: # yamllint disable-line rule:truthy
pull_request:
merge_group:
branches:
- main
push:
branches:
- main
permissions:
contents: read
jobs:
ansible_integration_test:
runs-on: ubuntu-latest
steps:
- name: Update pip, git
run: |
set -euxo pipefail
sudo apt-get update
- name: Checkout repo
uses: actions/checkout@v4
with:
path: ansible_collections/redhat_cop/vmware_ops

- name: Run
run: |
make integration
working-directory: ansible_collections/redhat_cop/vmware_ops
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
integration:
ansible-test integration --no-temp-workdir

51 changes: 51 additions & 0 deletions tests/expectations/mock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"httpRequest": {
"method": "POST",
"path": "/rest/com/vmware/cis/session"
},
"httpResponse": {
"statusCode": 200,
"body": {"value": "72300ca9ff16c5743fa0a6328c8570ce"}
}
},
{
"httpRequest": {
"method": "PUT",
"path": "/api/appliance/access/consolecli"
},
"httpResponse": {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{}"
}
},
{
"httpRequest": {
"method": "GET",
"path": "/api/appliance/access/consolecli"
},
"httpResponse": {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "true"
}
},
{
"httpRequest": {
"method" : "GET",
"path" : "/api/appliance/networking/firewall/inbound"
},
"httpResponse": {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": [{}]
}
}
]
2 changes: 2 additions & 0 deletions tests/integration/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testgroup]
testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/usr/bin/python3"
5 changes: 5 additions & 0 deletions tests/integration/targets/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2155,SC2086

BASE_DIR=$(dirname "${BASH_SOURCE[0]}")
export ANSIBLE_ROLES_PATH=${BASE_DIR}
26 changes: 26 additions & 0 deletions tests/integration/targets/prepare_rest/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Install dependencies
ansible.builtin.pip:
name:
- requests
- aiohttp

- name: Run rest
community.docker.docker_container:
name: vmwarest
image: mockserver/mockserver
state: started
recreate: yes
exposed_ports:
- 1080
ports:
- 1080:1080

- name: Pause
ansible.builtin.pause:
seconds: 10

- name: Put data to mockserver
ansible.builtin.command:
cmd: "curl -v -X PUT --data @../../../expectations/mock.json http://localhost:1080/mockserver/expectation"

15 changes: 15 additions & 0 deletions tests/integration/targets/security/run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- hosts: localhost
gather_facts: no
collections:
- community.general
vars_files:
- ../vars.yml

tasks:
- name: Vcsim
ansible.builtin.import_role:
name: prepare_rest

Check failure on line 11 in tests/integration/targets/security/run.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

syntax-check[specific]

the role 'prepare_rest' was not found in community.general:ansible.legacy:/home/runner/work/cloud.vmware_ops/cloud.vmware_ops/tests/integration/targets/security/roles:/home/runner/.cache/ansible-compat/c43c03/roles:/home/runner/work/cloud.vmware_ops/cloud.vmware_ops/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/cloud.vmware_ops/cloud.vmware_ops/tests/integration/targets/security

- name: Import drs rule role
ansible.builtin.import_role:
name: security
3 changes: 3 additions & 0 deletions tests/integration/targets/security/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
source ../init.sh
exec ansible-playbook run.yml
4 changes: 4 additions & 0 deletions tests/integration/targets/security/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Run
ansible.builtin.import_role:
name: redhat_cop.vmware_ops.security
6 changes: 6 additions & 0 deletions tests/integration/targets/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
security_hostname: "127.0.0.1:1080"
security_username: "user"
security_password: "pass"
security_validate_certs: false

security_consolecli_enabled: true

0 comments on commit 3576a53

Please sign in to comment.