-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from ephur/more_test_coverage
More test coverage
- Loading branch information
Showing
28 changed files
with
101 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020-2021 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2021 Richard Maynard ([email protected]) | ||
# Copyright 2021-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2021 Richard Maynard ([email protected]) | ||
# Copyright 2021-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -418,7 +418,7 @@ def tf_13cmd_options(rootc_options): | |
@pytest.fixture | ||
def definition_odict(): | ||
one_def = { | ||
"test": collections.OrderedDict( | ||
"test": dict( | ||
{ | ||
"path": "/test", | ||
"remote_vars": {"a": 1, "b": "two"}, | ||
|
@@ -427,7 +427,7 @@ def definition_odict(): | |
} | ||
) | ||
} | ||
return collections.OrderedDict(one_def) | ||
return dict(one_def) | ||
|
||
|
||
@pytest.fixture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -70,7 +70,7 @@ def test_make_vars(self, definition_odict, base, expected): | |
12, | ||
) | ||
test_vars = definition.make_vars( | ||
definition_odict[name].get("terraform_vars", collections.OrderedDict()), | ||
definition_odict[name].get("terraform_vars", dict()), | ||
base.get("terraform_vars"), | ||
) | ||
assert test_vars["c"] == expected | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -191,6 +191,7 @@ def test_check_conflicts(self, request, copier, cwp): | |
def test_get_destination(self, tmp_path, copier): | ||
dpath = f"{str(tmp_path)}/destination_test)" | ||
|
||
# test that get destination raises an error if destination is not set | ||
with pytest.raises(ValueError): | ||
copier.get_destination() | ||
|
||
|
@@ -203,6 +204,26 @@ def test_get_destination(self, tmp_path, copier): | |
assert copier.get_destination(make_dir=True) == dpath | ||
assert os.path.isdir(dpath) | ||
|
||
def test_get_destination_path(self, tmp_path, copier): | ||
"""Ensure the destination path is returned properly when destination is set""" | ||
dpath_td = tempfile.TemporaryDirectory() | ||
dpath = dpath_td.name | ||
|
||
# ensure object is in valid state for test | ||
with pytest.raises(AttributeError): | ||
getattr(copier, "_destination") | ||
|
||
assert copier.get_destination(**{"destination": dpath}) == dpath | ||
|
||
# ensure the directory is returned properly when make_dirs is true, and no errors | ||
# are raised when the directory already exists | ||
rpath = copier.get_destination(**{"destination": dpath, "make_dir": True}) | ||
assert rpath == dpath | ||
assert os.path.isdir(rpath) | ||
|
||
# remove the temporary directory | ||
del dpath_td | ||
|
||
|
||
class TestGitCopier: | ||
"""test the GitCopier copier""" | ||
|
@@ -262,12 +283,21 @@ def test_make_and_clean_temp(self): | |
"""tests making the temporary directory for git clones""" | ||
c = GitCopier("test_source") | ||
|
||
# ensure that the temp directory is created and attributes are set | ||
c.make_temp() | ||
assert hasattr(c, "_temp_dir") | ||
temp_dir = c._temp_dir | ||
assert os.path.isdir(temp_dir) | ||
assert hasattr(c, "_temp_dir") | ||
|
||
# ensure that the function is idempotent | ||
c.make_temp() | ||
# ensure that the temp directory is the same | ||
assert temp_dir == c._temp_dir | ||
assert os.path.isdir(c._temp_dir) | ||
assert hasattr(c, "_temp_dir") | ||
|
||
# ensure that the temp directory is removed | ||
c.clean_temp() | ||
assert not os.path.isdir(temp_dir) | ||
assert not hasattr(c, "_temp_dir") | ||
|
@@ -314,7 +344,23 @@ def test_type_match(self, request): | |
source="/tests/fixtures/definitions/test_a", | ||
root_path=f"{request.config.rootdir}", | ||
) | ||
|
||
# this should return true because the source is a valid directory | ||
assert FileSystemCopier.type_match(source) is True | ||
# this should return false because the full path to source does not exist inside of root_path | ||
assert ( | ||
FileSystemCopier.type_match("/some/invalid/path") | ||
is False | ||
) | ||
# this should return true because the full path to source exists inside of root_path | ||
assert ( | ||
FileSystemCopier.type_match( | ||
"/tests/fixtures/definitions/test_a", | ||
**{"root_path": f"{request.config.rootdir}"}, | ||
) | ||
is True | ||
) | ||
# this should return false because the source is not a valid directory | ||
assert FileSystemCopier.type_match("/some/invalid/path") is False | ||
|
||
@pytest.mark.parametrize( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env python | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
# Copyright 2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import click | ||
|
||
from tfworker.authenticators import AuthenticatorsCollection | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -19,7 +19,6 @@ | |
import re | ||
import shutil | ||
import tempfile | ||
from collections import OrderedDict | ||
|
||
import click | ||
import hcl2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -16,7 +16,6 @@ | |
import copy | ||
import json | ||
from pathlib import Path, PurePath | ||
from typing import OrderedDict | ||
|
||
import click | ||
import hcl2 | ||
|
@@ -58,13 +57,13 @@ def __init__( | |
self._body = body | ||
self._path = body.get("path") | ||
self._remote_vars = self.make_vars( | ||
body.get("remote_vars", collections.OrderedDict()), global_remote_vars | ||
body.get("remote_vars", dict()), global_remote_vars | ||
) | ||
self._terraform_vars = self.make_vars( | ||
body.get("terraform_vars", collections.OrderedDict()), global_terraform_vars | ||
body.get("terraform_vars", dict()), global_terraform_vars | ||
) | ||
self._template_vars = self.make_vars( | ||
body.get("template_vars", collections.OrderedDict()), {} | ||
body.get("template_vars", dict()), global_template_vars | ||
) | ||
|
||
self._deployment = deployment | ||
|
@@ -160,7 +159,7 @@ def quote_str(some_string): | |
|
||
def make_vars(self, local_vars, global_vars): | ||
"""Make a variables dictionary based on default vars, as well as specific vars for an item.""" | ||
global_vars = global_vars or collections.OrderedDict() | ||
global_vars = global_vars or dict() | ||
item_vars = copy.deepcopy(global_vars) | ||
for k, v in local_vars.items(): | ||
item_vars[k] = v | ||
|
@@ -188,7 +187,7 @@ def vars_typer(v, inner=False): | |
return rval | ||
else: | ||
return json.dumps(rval) | ||
elif isinstance(v, OrderedDict) or isinstance(v, dict): | ||
elif isinstance(v, dict): | ||
rval = {} | ||
for k, val in v.items(): | ||
result = Definition.vars_typer(val, inner=True) | ||
|
@@ -218,7 +217,7 @@ def __init__( | |
): | ||
self._body = definitions | ||
self._plan_for = plan_for | ||
self._definitions = collections.OrderedDict() | ||
self._definitions = dict() | ||
self._limit = True if len(limit) > 0 else False | ||
self._limit_size = len(limit) | ||
self._root_args = rootc.args | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -12,8 +12,6 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import OrderedDict | ||
|
||
from .base import BaseProvider | ||
|
||
|
||
|
@@ -43,7 +41,7 @@ def hcl(self): | |
result.append(f'provider "{self.tag}" {{') | ||
for k, v in provider_vars.items(): | ||
# Handle special case for kubernetes block in helm provider | ||
if k.lower() == "kubernetes" and isinstance(v, OrderedDict): | ||
if k.lower() == "kubernetes" and isinstance(v, dict): | ||
result.append(f" {k} {{") | ||
for ik, iv in v.items(): | ||
if iv and '"' not in iv: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2021 Richard Maynard ([email protected]) | ||
# Copyright 2021-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -206,7 +206,8 @@ def type_match(source: str, **kwargs) -> bool: | |
def make_temp(self) -> None: | ||
if hasattr(self, "_temp_dir"): | ||
pass | ||
self._temp_dir = tempfile.mkdtemp() | ||
else: | ||
self._temp_dir = tempfile.mkdtemp() | ||
|
||
def clean_temp(self) -> None: | ||
"""clean_temp removes the temporary path used by this copier""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2020 Richard Maynard ([email protected]) | ||
# Copyright 2020-2023 Richard Maynard ([email protected]) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|