Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
bsquizz committed Feb 11, 2022
1 parent 1610bca commit 22a2c5e
Showing 1 changed file with 209 additions and 15 deletions.
224 changes: 209 additions & 15 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import uuid

import pytest

from bonfire.processor import TemplateProcessor
from bonfire.utils import RepoFile


class MockRepoFile:
"""
mock of utils.RepoFile so that we do not literally fetch templates from github/gitlab/etc.
"""

templates = {}

def __init__(self, name):
@@ -75,36 +81,49 @@ def assert_clowdapps(items, app_list):
raise AssertionError("apps present more than once in processed output")


def test_dependencies(mock_repo_file):
def add_template(mock_repo_file, app_name, deps=[], optional_deps=[]):
mock_repo_file.add_template(
app_name,
uuid.uuid4().hex[0:6],
SIMPLE_CLOWDAPP.format(name=app_name, deps=deps, optional_deps=optional_deps),
)


@pytest.fixture()
def processor():
apps_config = {
"app1": {
"name": "app1",
"components": [
{"name": "app1-component1", "host": "local", "repo": "test", "path": "test"},
# {"name": "app1-component2", "host": "local", "repo": "test", "path": "test"},
# {"name": "app1-component3", "host": "local", "repo": "test", "path": "test"},
{"name": "app1-component2", "host": "local", "repo": "test", "path": "test"},
],
},
"app2": {
"name": "app2",
"components": [
{"name": "app2-component1", "host": "local", "repo": "test", "path": "test"},
{"name": "app2-component2", "host": "local", "repo": "test", "path": "test"},
{"name": "app2-component3", "host": "local", "repo": "test", "path": "test"},
],
},
"app3": {
"name": "app3",
"components": [
{"name": "app3-component1", "host": "local", "repo": "test", "path": "test"},
{"name": "app3-component2", "host": "local", "repo": "test", "path": "test"},
{"name": "app3-component3", "host": "local", "repo": "test", "path": "test"},
],
},
"app4": {
"name": "app4",
"components": [
{"name": "app4-component1", "host": "local", "repo": "test", "path": "test"},
{"name": "app4-component2", "host": "local", "repo": "test", "path": "test"},
],
},
}
tp = TemplateProcessor(
apps_config=apps_config,
app_names=["app1"],
app_names=[],
get_dependencies=True,
optional_deps_method="hybrid",
image_tag_overrides={},
@@ -118,17 +137,192 @@ def test_dependencies(mock_repo_file):
local=True,
frontends=False,
)
return tp

mock_repo_file.add_template(

@pytest.mark.parametrize(
"optional_deps_method,expected",
[
("all", ["app1-component1", "app1-component2", "app2-component2", "app3-component2"]),
("hybrid", ["app1-component1", "app1-component2", "app2-component2", "app3-component2"]),
("none", ["app1-component1", "app1-component2", "app2-component2", "app3-component2"]),
],
)
def test_required_deps(mock_repo_file, processor, optional_deps_method, expected):
"""
app1-component1 has 'app2-component2' listed under 'dependencies'
app2-component2 has 'app3-component2' listed under 'dependencies'
test that processing app1 results in expected ClowdApp dependencies being pulled in
"""
add_template(mock_repo_file, "app1-component1", deps=["app2-component2"])
add_template(mock_repo_file, "app1-component2")
add_template(mock_repo_file, "app2-component2", deps=["app3-component2"])
# template for app3-component2 will contain a dep we've already handled
add_template(mock_repo_file, "app3-component2", deps=["app1-component1"])

processor.optional_deps_method = optional_deps_method
processor.requested_app_names = ["app1"]
processed = processor.process()
assert_clowdapps(processed["items"], expected)


@pytest.mark.parametrize(
"optional_deps_method,expected",
[
("all", ["app1-component1", "app1-component2", "app2-component2", "app3-component2"]),
("hybrid", ["app1-component1", "app1-component2", "app2-component2"]),
("none", ["app1-component1", "app1-component2"]),
],
)
def test_optional_deps(mock_repo_file, processor, optional_deps_method, expected):
"""
app1-component1 has 'app2-component2' listed under 'optionalDependencies'
app2-component2 has 'app3-component2' listed under 'optionalDependencies'
test that processing app1 results in expected ClowdApp dependencies being pulled in depending
on what 'optional dependencies mode' is selected
"""
add_template(mock_repo_file, "app1-component1", optional_deps=["app2-component2"])
add_template(mock_repo_file, "app1-component2")
add_template(mock_repo_file, "app2-component2", optional_deps=["app3-component2"])
# template for app3-component2 will contain a dep we've already handled
add_template(mock_repo_file, "app3-component2", deps=["app1-component1"])

processor.optional_deps_method = optional_deps_method
processor.requested_app_names = ["app1"]
processed = processor.process()
assert_clowdapps(processed["items"], expected)


@pytest.mark.parametrize(
"optional_deps_method,expected",
[
(
"all",
[
"app1-component1",
"app1-component2",
"app2-component1",
"app2-component2",
"app3-component1",
"app3-component2",
],
),
(
"hybrid",
[
"app1-component1",
"app1-component2",
"app2-component1",
"app3-component1",
"app3-component2",
],
),
("none", ["app1-component1", "app1-component2", "app3-component1"]),
],
)
def test_mixed_deps(mock_repo_file, processor, optional_deps_method, expected):
"""
app1-component1 has 'app3-component1' listed under 'dependencies'
app1-component1 has 'app2-component1' listed under 'optionalDependencies'
app2-component1 has 'app3-component2' listed under 'dependencies'
app2-component1 has 'app2-component2' listed under 'optionalDependencies'
test that processing app1 results in expected ClowdApp dependencies being pulled in depending
on what 'optional dependencies mode' is selected
"""
add_template(
mock_repo_file,
"app1-component1",
"1234abc",
SIMPLE_CLOWDAPP.format(name="app1-component1", deps=["app2-component2"], optional_deps=[]),
deps=["app3-component1"],
optional_deps=["app2-component1"],
)
mock_repo_file.add_template(
"app2-component2",
"6789def",
SIMPLE_CLOWDAPP.format(name="app2-component2", deps=["app2-component2"], optional_deps=[]),
add_template(
mock_repo_file,
"app2-component1",
deps=["app3-component2"],
optional_deps=["app2-component2"],
)
add_template(mock_repo_file, "app1-component2")
add_template(mock_repo_file, "app2-component2")
add_template(mock_repo_file, "app3-component1")
add_template(mock_repo_file, "app3-component2")

processor.optional_deps_method = optional_deps_method
processor.requested_app_names = ["app1"]
processed = processor.process()
assert_clowdapps(processed["items"], expected)


@pytest.mark.parametrize(
"optional_deps_method,expected",
[
(
"all",
[
"app1-component1",
"app1-component2",
"app2-component1",
"app2-component2",
"app3-component1",
"app3-component2",
"app4-component1",
"app4-component2",
],
),
(
"hybrid",
[
"app1-component1",
"app1-component2",
"app2-component1",
"app2-component2",
"app3-component1",
"app3-component2",
],
),
(
"none",
[
"app1-component1",
"app1-component2",
"app2-component1",
"app3-component1",
"app3-component2",
],
),
],
)
def test_mixed_deps_two_apps(mock_repo_file, processor, optional_deps_method, expected):
"""
app1-component1 has 'app2-component1' listed under 'dependencies'
app1-component1 has 'app3-component1' listed under 'optionalDependencies'
app2-component1 has 'app4-component1' listed under 'optionalDependencies'
app2-component2 has 'app4-component2' listed under 'optionalDependencies'
app3-commponent1 has 'app2-component2' listed under 'optionalDependencies'
test that processing app1 and app3 results in expected ClowdApp dependencies being pulled in
depending on what 'optional dependencies mode' is selected
"""
add_template(
mock_repo_file,
"app1-component1",
deps=["app2-component1"],
optional_deps=["app3-component1"],
)
add_template(mock_repo_file, "app1-component2")
add_template(mock_repo_file, "app2-component1", optional_deps=["app4-component1"])
add_template(mock_repo_file, "app2-component2", optional_deps=["app4-component2"])
add_template(mock_repo_file, "app3-component1", optional_deps=["app2-component2"])
add_template(mock_repo_file, "app3-component2")
add_template(mock_repo_file, "app4-component1")
add_template(mock_repo_file, "app4-component2")

processed = tp.process()
assert_clowdapps(processed["items"], ["app1-component1", "app2-component2"])
processor.optional_deps_method = optional_deps_method
processor.requested_app_names = ["app1", "app3"]
processed = processor.process()
assert_clowdapps(processed["items"], expected)

0 comments on commit 22a2c5e

Please sign in to comment.