mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-06 02:40:29 -07:00
Adding a GitHub action to run ansible-test (#497)
As a first step to rehabilitate the google.cloud repository, adding actions to help ensure that the collection is still passing tests as changes are merged. Details: - ansible-devel was not added to the matrix since it may destablize the tests, primarily used to validate the collection. - running sanity tests reported over 100+ issues, backlogged to #498 before turning those on.
This commit is contained in:
parent
af3710889d
commit
f6d42b4bc1
2 changed files with 103 additions and 152 deletions
56
.github/workflows/ansible-test.yml
vendored
Normal file
56
.github/workflows/ansible-test.yml
vendored
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
name: "Run tests for the cloud.google collection"
|
||||||
|
on: [pull_request]
|
||||||
|
jobs:
|
||||||
|
# sanity tests cannot be turned on until #498 is resolved.
|
||||||
|
# sanity:
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
# defaults:
|
||||||
|
# run:
|
||||||
|
# working-directory: ansible_collections/google/cloud
|
||||||
|
# strategy:
|
||||||
|
# matrix:
|
||||||
|
# ansible_version:
|
||||||
|
# - stable-2.13
|
||||||
|
# - stable-2.11
|
||||||
|
# steps:
|
||||||
|
# - name: check out code
|
||||||
|
# uses: actions/checkout@v2
|
||||||
|
# with:
|
||||||
|
# path: ansible_collections/google/cloud
|
||||||
|
# - name: Set up Python
|
||||||
|
# uses: actions/setup-python@v1
|
||||||
|
# with:
|
||||||
|
# python-version: '3.8' # this is the minimum version required for Ansible 2.11
|
||||||
|
# - name: Install ansible-base (${{ matrix.ansible_version }})
|
||||||
|
# uses: nick-invision/retry@v2
|
||||||
|
# with:
|
||||||
|
# timeout_minutes: 3
|
||||||
|
# max_attempts: 3
|
||||||
|
# command: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible_version }}.tar.gz --disable-pip-version-check
|
||||||
|
# - name: Run sanity tests
|
||||||
|
# run: ansible-test sanity --docker -v --color --python 3.8
|
||||||
|
unit:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ansible_collections/google/cloud
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
ansible_version:
|
||||||
|
- stable-2.13
|
||||||
|
- stable-2.11
|
||||||
|
steps:
|
||||||
|
- name: check out code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: ansible_collections/google/cloud
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v1
|
||||||
|
with:
|
||||||
|
python-version: '3.8' # this is the minimum version required for Ansible 2.11
|
||||||
|
- name: Install dependencies
|
||||||
|
run: pip install -r requirements.txt
|
||||||
|
- name: Install ansible-base (${{ matrix.ansible_version }})
|
||||||
|
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible_version }}.tar.gz --disable-pip-version-check
|
||||||
|
- name: Run unit tests
|
||||||
|
run: ansible-test units --docker -v --color --python 3.8
|
|
@ -16,184 +16,109 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
from ansible_collections.community.general.tests.unit.compat import unittest
|
import unittest
|
||||||
from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import (GcpRequest,
|
from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import (
|
||||||
navigate_hash,
|
GcpRequest,
|
||||||
remove_nones_from_dict,
|
navigate_hash,
|
||||||
replace_resource_dict)
|
remove_nones_from_dict,
|
||||||
|
replace_resource_dict,
|
||||||
|
)
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
class ReplaceResourceDictTestCase(unittest.TestCase):
|
class ReplaceResourceDictTestCase(unittest.TestCase):
|
||||||
def test_given_dict(self):
|
def test_given_dict(self):
|
||||||
value = {
|
value = {"selfLink": "value"}
|
||||||
'selfLink': 'value'
|
self.assertEqual(replace_resource_dict(value, "selfLink"), value["selfLink"])
|
||||||
}
|
|
||||||
self.assertEqual(replace_resource_dict(value, 'selfLink'), value['selfLink'])
|
|
||||||
|
|
||||||
def test_given_array(self):
|
def test_given_array(self):
|
||||||
value = {
|
value = {"selfLink": "value"}
|
||||||
'selfLink': 'value'
|
self.assertEqual(
|
||||||
}
|
replace_resource_dict([value] * 3, "selfLink"), [value["selfLink"]] * 3
|
||||||
self.assertEqual(replace_resource_dict([value] * 3, 'selfLink'), [value['selfLink']] * 3)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NavigateHashTestCase(unittest.TestCase):
|
class NavigateHashTestCase(unittest.TestCase):
|
||||||
def test_one_level(self):
|
def test_one_level(self):
|
||||||
value = {
|
value = {"key": "value"}
|
||||||
'key': 'value'
|
self.assertEqual(navigate_hash(value, ["key"]), value["key"])
|
||||||
}
|
|
||||||
self.assertEqual(navigate_hash(value, ['key']), value['key'])
|
|
||||||
|
|
||||||
def test_multilevel(self):
|
def test_multilevel(self):
|
||||||
value = {
|
value = {"key": {"key2": "value"}}
|
||||||
'key': {
|
self.assertEqual(navigate_hash(value, ["key", "key2"]), value["key"]["key2"])
|
||||||
'key2': 'value'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.assertEqual(navigate_hash(value, ['key', 'key2']), value['key']['key2'])
|
|
||||||
|
|
||||||
def test_default(self):
|
def test_default(self):
|
||||||
value = {
|
value = {"key": "value"}
|
||||||
'key': 'value'
|
default = "not found"
|
||||||
}
|
self.assertEqual(navigate_hash(value, ["key", "key2"], default), default)
|
||||||
default = 'not found'
|
|
||||||
self.assertEqual(navigate_hash(value, ['key', 'key2'], default), default)
|
|
||||||
|
|
||||||
|
|
||||||
class RemoveNonesFromDictTestCase(unittest.TestCase):
|
class RemoveNonesFromDictTestCase(unittest.TestCase):
|
||||||
def test_remove_nones(self):
|
def test_remove_nones(self):
|
||||||
value = {
|
value = {"key": None, "good": "value"}
|
||||||
'key': None,
|
value_correct = {"good": "value"}
|
||||||
'good': 'value'
|
|
||||||
}
|
|
||||||
value_correct = {
|
|
||||||
'good': 'value'
|
|
||||||
}
|
|
||||||
self.assertEqual(remove_nones_from_dict(value), value_correct)
|
self.assertEqual(remove_nones_from_dict(value), value_correct)
|
||||||
|
|
||||||
def test_remove_empty_arrays(self):
|
def test_remove_empty_arrays(self):
|
||||||
value = {
|
value = {"key": [], "good": "value"}
|
||||||
'key': [],
|
value_correct = {"good": "value"}
|
||||||
'good': 'value'
|
|
||||||
}
|
|
||||||
value_correct = {
|
|
||||||
'good': 'value'
|
|
||||||
}
|
|
||||||
self.assertEqual(remove_nones_from_dict(value), value_correct)
|
self.assertEqual(remove_nones_from_dict(value), value_correct)
|
||||||
|
|
||||||
def test_remove_empty_dicts(self):
|
def test_remove_empty_dicts(self):
|
||||||
value = {
|
value = {"key": {}, "good": "value"}
|
||||||
'key': {},
|
value_correct = {"good": "value"}
|
||||||
'good': 'value'
|
|
||||||
}
|
|
||||||
value_correct = {
|
|
||||||
'good': 'value'
|
|
||||||
}
|
|
||||||
self.assertEqual(remove_nones_from_dict(value), value_correct)
|
self.assertEqual(remove_nones_from_dict(value), value_correct)
|
||||||
|
|
||||||
|
|
||||||
class GCPRequestDifferenceTestCase(unittest.TestCase):
|
class GCPRequestDifferenceTestCase(unittest.TestCase):
|
||||||
def test_simple_no_difference(self):
|
def test_simple_no_difference(self):
|
||||||
value1 = {
|
value1 = {"foo": "bar", "test": "original"}
|
||||||
'foo': 'bar',
|
|
||||||
'test': 'original'
|
|
||||||
}
|
|
||||||
request = GcpRequest(value1)
|
request = GcpRequest(value1)
|
||||||
self.assertEqual(request, request)
|
self.assertEqual(request, request)
|
||||||
|
|
||||||
def test_simple_different(self):
|
def test_simple_different(self):
|
||||||
value1 = {
|
value1 = {"foo": "bar", "test": "original"}
|
||||||
'foo': 'bar',
|
value2 = {"foo": "bar", "test": "different"}
|
||||||
'test': 'original'
|
difference = {"test": "original"}
|
||||||
}
|
|
||||||
value2 = {
|
|
||||||
'foo': 'bar',
|
|
||||||
'test': 'different'
|
|
||||||
}
|
|
||||||
difference = {
|
|
||||||
'test': 'original'
|
|
||||||
}
|
|
||||||
request1 = GcpRequest(value1)
|
request1 = GcpRequest(value1)
|
||||||
request2 = GcpRequest(value2)
|
request2 = GcpRequest(value2)
|
||||||
self.assertNotEquals(request1, request2)
|
self.assertNotEquals(request1, request2)
|
||||||
self.assertEqual(request1.difference(request2), difference)
|
self.assertEqual(request1.difference(request2), difference)
|
||||||
|
|
||||||
def test_nested_dictionaries_no_difference(self):
|
def test_nested_dictionaries_no_difference(self):
|
||||||
value1 = {
|
value1 = {"foo": {"quiet": {"tree": "test"}, "bar": "baz"}, "test": "original"}
|
||||||
'foo': {
|
|
||||||
'quiet': {
|
|
||||||
'tree': 'test'
|
|
||||||
},
|
|
||||||
'bar': 'baz'
|
|
||||||
},
|
|
||||||
'test': 'original'
|
|
||||||
}
|
|
||||||
request = GcpRequest(value1)
|
request = GcpRequest(value1)
|
||||||
self.assertEqual(request, request)
|
self.assertEqual(request, request)
|
||||||
|
|
||||||
def test_nested_dictionaries_with_difference(self):
|
def test_nested_dictionaries_with_difference(self):
|
||||||
value1 = {
|
value1 = {"foo": {"quiet": {"tree": "test"}, "bar": "baz"}, "test": "original"}
|
||||||
'foo': {
|
value2 = {"foo": {"quiet": {"tree": "baz"}, "bar": "hello"}, "test": "original"}
|
||||||
'quiet': {
|
difference = {"foo": {"quiet": {"tree": "test"}, "bar": "baz"}}
|
||||||
'tree': 'test'
|
|
||||||
},
|
|
||||||
'bar': 'baz'
|
|
||||||
},
|
|
||||||
'test': 'original'
|
|
||||||
}
|
|
||||||
value2 = {
|
|
||||||
'foo': {
|
|
||||||
'quiet': {
|
|
||||||
'tree': 'baz'
|
|
||||||
},
|
|
||||||
'bar': 'hello'
|
|
||||||
},
|
|
||||||
'test': 'original'
|
|
||||||
}
|
|
||||||
difference = {
|
|
||||||
'foo': {
|
|
||||||
'quiet': {
|
|
||||||
'tree': 'test'
|
|
||||||
},
|
|
||||||
'bar': 'baz'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request1 = GcpRequest(value1)
|
request1 = GcpRequest(value1)
|
||||||
request2 = GcpRequest(value2)
|
request2 = GcpRequest(value2)
|
||||||
self.assertNotEquals(request1, request2)
|
self.assertNotEquals(request1, request2)
|
||||||
self.assertEqual(request1.difference(request2), difference)
|
self.assertEqual(request1.difference(request2), difference)
|
||||||
|
|
||||||
def test_arrays_strings_no_difference(self):
|
def test_arrays_strings_no_difference(self):
|
||||||
value1 = {
|
value1 = {"foo": ["baz", "bar"]}
|
||||||
'foo': [
|
|
||||||
'baz',
|
|
||||||
'bar'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
request = GcpRequest(value1)
|
request = GcpRequest(value1)
|
||||||
self.assertEqual(request, request)
|
self.assertEqual(request, request)
|
||||||
|
|
||||||
def test_arrays_strings_with_difference(self):
|
def test_arrays_strings_with_difference(self):
|
||||||
value1 = {
|
value1 = {
|
||||||
'foo': [
|
"foo": [
|
||||||
'baz',
|
"baz",
|
||||||
'bar',
|
"bar",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
value2 = {
|
value2 = {"foo": ["baz", "hello"]}
|
||||||
'foo': [
|
|
||||||
'baz',
|
|
||||||
'hello'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
difference = {
|
difference = {
|
||||||
'foo': [
|
"foo": [
|
||||||
'bar',
|
"bar",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
request1 = GcpRequest(value1)
|
request1 = GcpRequest(value1)
|
||||||
|
@ -202,48 +127,18 @@ class GCPRequestDifferenceTestCase(unittest.TestCase):
|
||||||
self.assertEqual(request1.difference(request2), difference)
|
self.assertEqual(request1.difference(request2), difference)
|
||||||
|
|
||||||
def test_arrays_dicts_with_no_difference(self):
|
def test_arrays_dicts_with_no_difference(self):
|
||||||
value1 = {
|
value1 = {"foo": [{"test": "value", "foo": "bar"}, {"different": "dict"}]}
|
||||||
'foo': [
|
|
||||||
{
|
|
||||||
'test': 'value',
|
|
||||||
'foo': 'bar'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'different': 'dict'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
request = GcpRequest(value1)
|
request = GcpRequest(value1)
|
||||||
self.assertEqual(request, request)
|
self.assertEqual(request, request)
|
||||||
|
|
||||||
def test_arrays_dicts_with_difference(self):
|
def test_arrays_dicts_with_difference(self):
|
||||||
value1 = {
|
value1 = {"foo": [{"test": "value", "foo": "bar"}, {"different": "dict"}]}
|
||||||
'foo': [
|
|
||||||
{
|
|
||||||
'test': 'value',
|
|
||||||
'foo': 'bar'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'different': 'dict'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
value2 = {
|
value2 = {
|
||||||
'foo': [
|
"foo": [
|
||||||
{
|
{"test": "value2", "foo": "bar2"},
|
||||||
'test': 'value2',
|
|
||||||
'foo': 'bar2'
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
difference = {
|
|
||||||
'foo': [
|
|
||||||
{
|
|
||||||
'test': 'value',
|
|
||||||
'foo': 'bar'
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
difference = {"foo": [{"test": "value", "foo": "bar"}]}
|
||||||
request1 = GcpRequest(value1)
|
request1 = GcpRequest(value1)
|
||||||
request2 = GcpRequest(value2)
|
request2 = GcpRequest(value2)
|
||||||
self.assertNotEquals(request1, request2)
|
self.assertNotEquals(request1, request2)
|
||||||
|
|
Loading…
Add table
Reference in a new issue