Skip to content

Commit

Permalink
add basic unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kukushkin <kukushkin.anton@gmail.com>
  • Loading branch information
kukushking committed Feb 14, 2024
1 parent f2f2269 commit 42199f7
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 1 deletion.
3 changes: 3 additions & 0 deletions modules/mlflow/mlflow-fargate/coverage.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit =
tests/*
254 changes: 254 additions & 0 deletions modules/mlflow/mlflow-fargate/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --output-file=requirements-dev.txt requirements-dev.in
#
annotated-types==0.6.0
# via pydantic
attrs==23.2.0
# via
# cattrs
# jschema-to-python
# jsii
# jsonschema
# referencing
# sarif-om
aws-cdk-asset-awscli-v1==2.2.202
# via aws-cdk-lib
aws-cdk-asset-kubectl-v20==2.1.2
# via aws-cdk-lib
aws-cdk-asset-node-proxy-agent-v6==2.0.1
# via aws-cdk-lib
aws-cdk-lib==2.127.0
# via cdk-nag
aws-sam-translator==1.84.0
# via cfn-lint
awscli==1.32.41
# via -r requirements-dev.in
black==24.2.0
# via -r requirements-dev.in
boto3==1.34.41
# via aws-sam-translator
botocore==1.34.41
# via
# awscli
# boto3
# s3transfer
build==1.0.3
# via
# check-manifest
# pip-tools
# pyroma
cattrs==23.2.3
# via jsii
cdk-nag==2.28.34
# via -r requirements-dev.in
certifi==2024.2.2
# via requests
cfn-lint==0.85.1
# via -r requirements-dev.in
charset-normalizer==3.3.2
# via requests
check-manifest==0.49
# via -r requirements-dev.in
click==8.1.7
# via
# black
# pip-tools
colorama==0.4.4
# via awscli
constructs==10.3.0
# via
# aws-cdk-lib
# cdk-nag
docutils==0.16
# via
# awscli
# pyroma
exceptiongroup==1.2.0
# via
# cattrs
# pytest
flake8==7.0.0
# via -r requirements-dev.in
idna==3.6
# via requests
importlib-metadata==7.0.1
# via build
importlib-resources==6.1.1
# via jsii
iniconfig==2.0.0
# via pytest
isort==5.13.2
# via -r requirements-dev.in
jmespath==1.0.1
# via
# boto3
# botocore
jschema-to-python==1.2.3
# via cfn-lint
jsii==1.94.0
# via
# aws-cdk-asset-awscli-v1
# aws-cdk-asset-kubectl-v20
# aws-cdk-asset-node-proxy-agent-v6
# aws-cdk-lib
# cdk-nag
# constructs
jsonpatch==1.33
# via cfn-lint
jsonpickle==3.0.2
# via jschema-to-python
jsonpointer==2.4
# via jsonpatch
jsonschema==4.21.1
# via
# aws-sam-translator
# cfn-lint
jsonschema-specifications==2023.12.1
# via jsonschema
junit-xml==1.9
# via cfn-lint
mccabe==0.7.0
# via flake8
mpmath==1.3.0
# via sympy
mypy==1.8.0
# via -r requirements-dev.in
mypy-extensions==1.0.0
# via
# black
# mypy
networkx==3.2.1
# via cfn-lint
packaging==23.2
# via
# black
# build
# pyroma
# pytest
pathspec==0.12.1
# via black
pbr==6.0.0
# via
# jschema-to-python
# sarif-om
pip-tools==7.3.0
# via -r requirements-dev.in
platformdirs==4.2.0
# via black
pluggy==1.4.0
# via pytest
publication==0.0.3
# via
# aws-cdk-asset-awscli-v1
# aws-cdk-asset-kubectl-v20
# aws-cdk-asset-node-proxy-agent-v6
# aws-cdk-lib
# cdk-nag
# constructs
# jsii
pyasn1==0.5.1
# via rsa
pycodestyle==2.11.1
# via flake8
pydantic==2.6.1
# via aws-sam-translator
pydantic-core==2.16.2
# via pydantic
pydot==2.0.0
# via -r requirements-dev.in
pyflakes==3.2.0
# via flake8
pygments==2.17.2
# via pyroma
pyparsing==3.1.1
# via pydot
pyproject-hooks==1.0.0
# via build
pyroma==4.2
# via -r requirements-dev.in
pytest==8.0.0
# via -r requirements-dev.in
python-dateutil==2.8.2
# via
# botocore
# jsii
pyyaml==6.0.1
# via
# awscli
# cfn-lint
referencing==0.33.0
# via
# jsonschema
# jsonschema-specifications
regex==2023.12.25
# via cfn-lint
requests==2.31.0
# via pyroma
rpds-py==0.18.0
# via
# jsonschema
# referencing
rsa==4.7.2
# via awscli
s3transfer==0.10.0
# via
# awscli
# boto3
sarif-om==1.0.4
# via cfn-lint
six==1.16.0
# via
# junit-xml
# python-dateutil
sympy==1.12
# via cfn-lint
tomli==2.0.1
# via
# black
# build
# check-manifest
# mypy
# pip-tools
# pyproject-hooks
# pytest
trove-classifiers==2024.1.31
# via pyroma
typeguard==2.13.3
# via
# aws-cdk-asset-awscli-v1
# aws-cdk-asset-kubectl-v20
# aws-cdk-asset-node-proxy-agent-v6
# aws-cdk-lib
# cdk-nag
# constructs
# jsii
types-pyyaml==6.0.12.12
# via -r requirements-dev.in
types-setuptools==69.0.0.20240125
# via -r requirements-dev.in
typing-extensions==4.9.0
# via
# aws-sam-translator
# black
# cattrs
# jsii
# mypy
# pydantic
# pydantic-core
urllib3==1.26.18
# via
# botocore
# requests
wheel==0.42.0
# via pip-tools
zipp==3.17.0
# via
# importlib-metadata
# importlib-resources

# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools
Empty file.
46 changes: 46 additions & 0 deletions modules/mlflow/mlflow-fargate/tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import sys

import pytest


@pytest.fixture(scope="function")
def stack_defaults():
os.environ["SEEDFARMER_PROJECT_NAME"] = "test-project"
os.environ["SEEDFARMER_DEPLOYMENT_NAME"] = "test-deployment"
os.environ["SEEDFARMER_MODULE_NAME"] = "test-module"
os.environ["CDK_DEFAULT_ACCOUNT"] = "111111111111"
os.environ["CDK_DEFAULT_REGION"] = "us-east-1"

os.environ["SEEDFARMER_PARAMETER_VPC_ID"] = "vpc-12345"
os.environ["SEEDFARMER_PARAMETER_ECR_REPOSITORY_NAME"] = "repo5"
os.environ["SEEDFARMER_PARAMETER_ARTIFACTS_BUCKET_NAME"] = "bucket"

# Unload the app import so that subsequent tests don't reuse
if "app" in sys.modules:
del sys.modules["app"]


def test_app(stack_defaults):
import app # noqa: F401


def test_vpc_id(stack_defaults):
del os.environ["SEEDFARMER_PARAMETER_VPC_ID"]

with pytest.raises(Exception, match="Missing input parameter vpc-id"):
import app # noqa: F401


def test_ecr_repository_name(stack_defaults):
del os.environ["SEEDFARMER_PARAMETER_ECR_REPOSITORY_NAME"]

with pytest.raises(Exception, match="Missing input parameter ecr-repository-name"):
import app # noqa: F401


def test_artifacts_bucket_name(stack_defaults):
del os.environ["SEEDFARMER_PARAMETER_ARTIFACTS_BUCKET_NAME"]

with pytest.raises(Exception, match="Missing input parameter artifacts-bucket-name"):
import app # noqa: F401
56 changes: 56 additions & 0 deletions modules/mlflow/mlflow-fargate/tests/test_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import sys

import aws_cdk as cdk
import pytest
from aws_cdk.assertions import Template


@pytest.fixture(scope="function")
def stack_defaults() -> None:
os.environ["CDK_DEFAULT_ACCOUNT"] = "111111111111"
os.environ["CDK_DEFAULT_REGION"] = "us-east-1"

# Unload the app import so that subsequent tests don't reuse
if "stack" in sys.modules:
del sys.modules["stack"]


def test_synthesize_stack() -> None:
import stack

app = cdk.App()

project_name = "test-project"
dep_name = "test-deployment"
mod_name = "test-module"
app_prefix = f"{project_name}-{dep_name}-{mod_name}"

vpc_id = "vpc-123"
subnet_ids = []
ecr_repo_name = "repo"
task_cpu_units = 4 * 1024
task_memory_limit_mb = 8 * 1024
artifacts_bucket_name = "bucket"

stack = stack.MlflowFargateStack(
scope=app,
id=app_prefix,
app_prefix=app_prefix,
vpc_id=vpc_id,
subnet_ids=subnet_ids,
ecs_cluster_name=None,
service_name=None,
ecr_repo_name=ecr_repo_name,
task_cpu_units=task_cpu_units,
task_memory_limit_mb=task_memory_limit_mb,
artifacts_bucket_name=artifacts_bucket_name,
env=cdk.Environment(
account=os.environ["CDK_DEFAULT_ACCOUNT"],
region=os.environ["CDK_DEFAULT_REGION"],
),
)

template = Template.from_stack(stack)
template.resource_count_is("AWS::ECS::Cluster", 1)
template.resource_count_is("AWS::ECS::TaskDefinition", 1)
2 changes: 1 addition & 1 deletion modules/mlflow/mlflow-image/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile requirements-dev.in
# pip-compile --output-file=requirements-dev.txt requirements-dev.in
#
aiohttp==3.9.2
# via black
Expand Down
Empty file.
Loading

0 comments on commit 42199f7

Please sign in to comment.