Skip to content

Commit a77c914

Browse files
committed
Switch to ansible-test style testing
1 parent 97bff2f commit a77c914

9 files changed

Lines changed: 519 additions & 345 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ jobs:
2929
run: poetry install
3030
if: steps.cache.outputs.cache-hit != 'true'
3131

32-
- name: Test ansible collection
33-
env:
34-
PYTHONPATH: collections
35-
working-directory: ansible
36-
run: poetry run pytest
32+
- name: Unit test ansible collection
33+
working-directory: ansible/collections/ansible_collections/nhsd/apigee
34+
run: poetry run ansible-test units --python=3.8
35+
36+
- name: Integration test ansible collection
37+
working-directory: ansible/collections/ansible_collections/nhsd/apigee
38+
run: poetry run ansible-test integration --python=3.8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

ansible/collections/ansible_collections/nhsd/apigee/tests/unit/plugins/module_utils/models/manifest/test_manifests/canary-v1.0.0.yml renamed to ansible/collections/ansible_collections/nhsd/apigee/tests/integration/targets/test_validate_manifest/files/canary-api-v1.0.0/manifest.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ meta:
66
apigee:
77
environments:
88
- name: internal-dev
9-
proxies:
10-
- name: canary-api-internal-dev
11-
path: proxies/live
129
api_catalog:
1310
- anonAllowed: true
1411
description: tweet tweet!
@@ -39,9 +36,6 @@ apigee:
3936
- name: canary-api-internal-dev
4037
path: canary-api.json
4138
- name: internal-qa
42-
proxies:
43-
- name: canary-api-internal-qa
44-
path: proxies/live
4539
api_catalog:
4640
- anonAllowed: true
4741
description: tweet tweet!

ansible/collections/ansible_collections/nhsd/apigee/tests/unit/plugins/module_utils/models/manifest/test_manifests/pds-v1.0.0.yml renamed to ansible/collections/ansible_collections/nhsd/apigee/tests/integration/targets/test_validate_manifest/files/personal-demographics-service-v1.0.0/manifest.yml

File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- name: get test manifest files + path to dummy specs
2+
find:
3+
paths: "{{ role_path }}/files"
4+
recurse: yes
5+
file_type: directory
6+
register: find_dist_dirs
7+
8+
- name: check test dist_dirs files were found
9+
assert:
10+
that:
11+
- "{{ find_dist_dirs.matched > 0 }}"
12+
13+
- name: extract dist dirs
14+
set_fact:
15+
DIST_DIRS: "{{ find_dist_dirs | json_query('files[*].path') | list }}"
16+
17+
- name: validate test manifest files
18+
include_role:
19+
name: validate_manifest
20+
loop: "{{ DIST_DIRS }}"
21+
loop_control:
22+
loop_var: DIST_DIR
Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import os
21
import json
32
import pathlib
4-
import yaml
5-
import re
63

74
from ansible_collections.nhsd.apigee.plugins.module_utils.models.manifest.manifest import (
85
Manifest,
6+
)
7+
from ansible_collections.nhsd.apigee.plugins.module_utils.models.manifest.meta import (
98
SCHEMA_VERSION,
109
)
1110

@@ -25,30 +24,3 @@ def test_schema_version():
2524
with open(str(DIR) + f'/schema_versions/v{SCHEMA_VERSION}.json') as f:
2625
recorded_schema = json.load(f)
2726
assert live_schema == recorded_schema
28-
29-
30-
def test_all_example_schemas_can_be_loaded(tmp_path):
31-
"""
32-
Validate all example manifests on the current major version of the
33-
SCHEMA_VERSION
34-
"""
35-
36-
# Setup a tmpdir containing dummy spec files as their existance is validated.
37-
for spec_name in ["personal-demographics.json", "canary-api.json"]:
38-
file_name = str(tmp_path) + f"/{spec_name}"
39-
with open(file_name, "w") as f:
40-
f.write("{}")
41-
os.chdir(tmp_path)
42-
43-
# i.e. something like: pds-v1.2.3.yml
44-
version_pattern = re.compile(r"v([0-9]+)\.([0-9]+)\.([0-9]+)\.yml$")
45-
for path in DIR.glob("test_manifests/*"):
46-
match = re.search(version_pattern, path.name)
47-
if match:
48-
major, minor, patch = [int(match.group(x)) for x in range(1, 4)]
49-
# If same major version and ahead all patches...
50-
if MAJOR == major and MINOR >= minor and PATCH >= patch:
51-
with open(str(path)) as f:
52-
manifest = yaml.load(f, yaml.SafeLoader)
53-
# Will error if schema invalid
54-
Manifest(**manifest, dist_dir=str(tmp_path))

0 commit comments

Comments
 (0)