Github action for unit and sanity tests (#172)

pull/177/head^2
Bradley A. Thornton 2022-05-16 09:52:15 -07:00 committed by GitHub
parent 54a2269fd9
commit 5a53c19804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 122 additions and 78 deletions

26
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,26 @@
name: Test collection
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
sanity:
uses: ansible-network/github_actions/.github/workflows/sanity.yml@main
unit-galaxy:
uses: ansible-network/github_actions/.github/workflows/unit_simple.yml@main
all_green:
if: ${{ always() }}
needs:
- sanity
- unit-galaxy
runs-on: ubuntu-latest
steps:
- run: >-
python -c "assert set([
'${{ needs.sanity.result }}',
'${{ needs.unit-galaxy.result }}'
]) == {'success'}"

View File

@ -0,0 +1,4 @@
---
trivial:
- Enable GH action for unit ans sanity tests
- Several minor doc string updates to get sanity to pass with devel/milestone

View File

@ -23,20 +23,21 @@ DOCUMENTATION = """
- Using the parameters below- C(lookup('ansible.utils.get_path', var, path, wantlist)) - Using the parameters below- C(lookup('ansible.utils.get_path', var, path, wantlist))
options: options:
var: var:
description: The variable from which the value should be extracted. description:
- The variable from which the value should be extracted.
type: raw type: raw
required: True required: True
path: path:
description: > description:
The I(path) in the I(var) to retrieve the value of. - The I(path) in the I(var) to retrieve the value of.
The I(path) needs to a be a valid jinja path. - The I(path) needs to a be a valid jinja path.
type: str type: str
required: True required: True
wantlist: wantlist:
description: > description:
If set to C(True), the return value will always be a list. - If set to C(True), the return value will always be a list.
This can also be accomplished using C(query) or C(q) instead of C(lookup). - This can also be accomplished using C(query) or C(q) instead of C(lookup).
U(https://docs.ansible.com/ansible/latest/plugins/lookup.html). - U(https://docs.ansible.com/ansible/latest/plugins/lookup.html).
type: bool type: bool
notes: notes:
@ -170,8 +171,10 @@ class LookupModule(LookupBase):
keys = ["var", "path"] keys = ["var", "path"]
terms = dict(zip(keys, terms)) terms = dict(zip(keys, terms))
terms.update(kwargs) terms.update(kwargs)
schema = [v for k, v in globals() if k.lower() == "documentation"]
aav = AnsibleArgSpecValidator( aav = AnsibleArgSpecValidator(
data=terms, schema=DOCUMENTATION, name="get_path" data=terms, schema=schema[0], name="get_path"
) )
valid, errors, updated_data = aav.validate() valid, errors, updated_data = aav.validate()
if not valid: if not valid:

View File

@ -17,45 +17,47 @@ DOCUMENTATION = """
author: Bradley Thornton (@cidrblock) author: Bradley Thornton (@cidrblock)
version_added: "1.0.0" version_added: "1.0.0"
short_description: Find the indices of items in a list matching some criteria short_description: Find the indices of items in a list matching some criteria
description: description: foo
- This plugin returns the indices of items matching some criteria in a list. - This plugin returns the indices of items matching some criteria in a list.
- When working with a list of dictionaries, the key to evaluate can be specified. - When working with a list of dictionaries, the key to evaluate can be specified.
- B(index_of) is also available as a B(filter plugin) for convenience. - B(index_of) is also available as a B(filter plugin) for convenience.
- Using the parameters below- C(lookup('ansible.utils.index_of', data, test, value, key, fail_on_missing, wantlist)). - Using the parameters below- C(lookup('ansible.utils.index_of', data, test, value, key, fail_on_missing, wantlist)).
options: options:
data: data:
description: A list of items to enumerate and test against. description:
- A list of items to enumerate and test against.
type: list type: list
elements: raw elements: raw
required: True required: True
test: test:
description: > description:
The name of the test to run against the list, a valid jinja2 test or ansible test plugin. - The name of the test to run against the list, a valid jinja2 test or ansible test plugin.
Jinja2 includes the following tests U(http://jinja.palletsprojects.com/templates/#builtin-tests). - Jinja2 includes the following tests U(http://jinja.palletsprojects.com/templates/#builtin-tests).
An overview of tests included in ansible U(https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html). - An overview of tests included in ansible U(https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html).
type: str type: str
required: True required: True
value: value:
description: > description:
The value used to test each list item against. - The value used to test each list item against.
Not required for simple tests (eg: C(true), C(false), C(even), C(odd)) - Not required for simple tests (e.g. C(true), C(false), C(even), C(odd))
May be a C(string), C(boolean), C(number), C(regular expression) C(dict) and so on, depending on the B(test) used. - May be a C(string), C(boolean), C(number), C(regular expression) C(dict) and so on, depending on the B(test) used.
type: raw type: raw
key: key:
description: > description:
When the data provided is a list of dictionaries, run the test against this dictionary key. - When the data provided is a list of dictionaries, run the test against this dictionary key.
When using a I(key), the I(data) must only contain dictionaries. - When using a I(key), the I(data) must only contain dictionaries.
See I(fail_on_missing) below to determine the behaviour when the I(key) is missing from a dictionary in the I(data). - See I(fail_on_missing) below to determine the behaviour when the I(key) is missing from a dictionary in the I(data).
type: str type: str
fail_on_missing: fail_on_missing:
description: When provided a list of dictionaries, fail if the key is missing from one or more of the dictionaries. description:
- When provided a list of dictionaries, fail if the key is missing from one or more of the dictionaries.
type: bool type: bool
wantlist: wantlist:
description: > description:
When only a single entry in the I(data) is matched, the index of that entry is returned as an integer. - When only a single entry in the I(data) is matched, the index of that entry is returned as an integer.
If set to C(True), the return value will always be a list, even if only a single entry is matched. - If set to C(True), the return value will always be a list, even if only a single entry is matched.
This can also be accomplished using C(query) or C(q) instead of C(lookup). - This can also be accomplished using C(query) or C(q) instead of C(lookup).
U(https://docs.ansible.com/ansible/latest/plugins/lookup.html) - U(https://docs.ansible.com/ansible/latest/plugins/lookup.html)
type: bool type: bool
notes: notes:
@ -338,8 +340,10 @@ class LookupModule(LookupBase):
] ]
terms = dict(zip(keys, terms)) terms = dict(zip(keys, terms))
terms.update(kwargs) terms.update(kwargs)
schema = [v for k, v in globals() if k.lower() == "documentation"]
aav = AnsibleArgSpecValidator( aav = AnsibleArgSpecValidator(
data=terms, schema=DOCUMENTATION, name="index_of" data=terms, schema=schema[0], name="index_of"
) )
valid, errors, updated_data = aav.validate() valid, errors, updated_data = aav.validate()
if not valid: if not valid:

View File

@ -25,18 +25,20 @@ DOCUMENTATION = """
- Using the parameters below- C(lookup('ansible.utils.to_paths', var, prepend, wantlist)) - Using the parameters below- C(lookup('ansible.utils.to_paths', var, prepend, wantlist))
options: options:
var: var:
description: The value of I(var) will be used. description:
- The value of I(var) will be used.
type: raw type: raw
required: True required: True
prepend: prepend:
description: Prepend each path entry. Useful to add the initial I(var) name. description:
- Prepend each path entry. Useful to add the initial I(var) name.
type: str type: str
required: False required: False
wantlist: wantlist:
description: > description:
If set to I(True), the return value will always be a list. - If set to I(True), the return value will always be a list.
This can also be accomplished using C(query) or B(q) instead of C(lookup). - This can also be accomplished using C(query) or B(q) instead of C(lookup).
U(https://docs.ansible.com/ansible/latest/plugins/lookup.html) - U(https://docs.ansible.com/ansible/latest/plugins/lookup.html)
type: bool type: bool
notes: notes:
@ -141,8 +143,10 @@ class LookupModule(LookupBase):
keys = ["var", "prepend"] keys = ["var", "prepend"]
terms = dict(zip(keys, terms)) terms = dict(zip(keys, terms))
terms.update(kwargs) terms.update(kwargs)
schema = [v for k, v in globals() if k.lower() == "documentation"]
aav = AnsibleArgSpecValidator( aav = AnsibleArgSpecValidator(
data=terms, schema=DOCUMENTATION, name="to_paths" data=terms, schema=schema[0], name="to_paths"
) )
valid, errors, updated_data = aav.validate() valid, errors, updated_data = aav.validate()
if not valid: if not valid:

View File

@ -109,9 +109,12 @@ class LookupModule(LookupBase):
if kwargs.get("engine"): if kwargs.get("engine"):
params.update({"engine": kwargs["engine"]}) params.update({"engine": kwargs["engine"]})
schema = [
v for k, v in globals().items() if k.lower() == "documentation"
]
valid, argspec_result, updated_params = check_argspec( valid, argspec_result, updated_params = check_argspec(
DOCUMENTATION, schema=schema[0],
"validate lookup", name="validate lookup",
schema_conditionals=ARGSPEC_CONDITIONALS, schema_conditionals=ARGSPEC_CONDITIONALS,
**params **params
) )