Skip to content

Commit

Permalink
tests: add tests for Glue component
Browse files Browse the repository at this point in the history
  • Loading branch information
farbodahm committed Oct 11, 2024
1 parent 93219a1 commit e5730f8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/damavand/cloud/aws/controllers/spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ def __init__(
**kwargs,
) -> None:
super().__init__(name, applications, tags, **kwargs)
print("\n\n\nShit")
self._glue_client = boto3.client("glue", region_name=region)

@buildtime
@cache
def resource(self) -> PulumiResource:
print("\n\n\nI'm called")
if not self.applications:
raise BuildtimeException("No applications found to create Glue jobs.")

Expand Down
93 changes: 91 additions & 2 deletions tests/clouds/aws/resources/test_glue_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import pulumi_aws as aws
from pulumi.runtime.mocks import MockResourceArgs, MockCallArgs

from damavand.cloud.aws.resources.glue_component import GlueJobDefinition


# NOTE: this has to be defined before importing infrastructure codes.
# Check Pulumi's documentation for more details: https://www.pulumi.com/docs/using-pulumi/testing/unit/
Expand All @@ -25,6 +23,11 @@ def call(self, args: MockCallArgs) -> Tuple[dict, Optional[List[Tuple[str, str]]
)

from damavand.cloud.aws.resources import GlueComponent, GlueComponentArgs # noqa: E402
from damavand.cloud.aws.resources.glue_component import ( # noqa: E402
GlueJobDefinition,
ConnectorConfig,
GlueJobType,
)


@pytest.fixture
Expand Down Expand Up @@ -93,3 +96,89 @@ def should_name_have_prefix(names: list[str]):
pulumi.Output.all(glue_component.jobs).apply(should_have_two)
for job in glue_component.jobs:
pulumi.Output.all(job.name).apply(should_name_have_prefix)


@pulumi.runtime.test
def test_code_repository_bucket(glue_component):
def should_have_one_bucket(buckets: list[aws.s3.BucketV2]):
assert len(buckets) == 1

pulumi.Output.all(glue_component.code_repository_bucket).apply(
should_have_one_bucket
)


@pulumi.runtime.test
def test_iceberg_database(glue_component):
def should_have_one_database(dbs: list[aws.glue.CatalogDatabase]):
assert len(dbs) == 1

pulumi.Output.all(glue_component.iceberg_database).apply(should_have_one_database)


@pulumi.runtime.test
def test_kafka_checkpoint_bucket(glue_component):
def should_not_create_bucket_if_no_streaming(
buckets: list[Optional[aws.s3.BucketV2]],
):
assert buckets[0] is None

pulumi.Output.all(glue_component.kafka_checkpoint_bucket).apply(
should_not_create_bucket_if_no_streaming
)


@pytest.fixture
def glue_component_with_streaming_job():
return GlueComponent(
name="test-streaming",
args=GlueComponentArgs(
jobs=[
GlueJobDefinition(
name="streaming-job",
description="test streaming job",
job_type=GlueJobType.GLUE_STREAMING,
),
]
),
)


@pulumi.runtime.test
def test_kafka_checkpoint_bucket_streaming(glue_component_with_streaming_job):
def should_create_bucket_for_streaming(buckets: list[aws.s3.BucketV2]):
assert len(buckets) == 1

pulumi.Output.all(glue_component_with_streaming_job.kafka_checkpoint_bucket).apply(
should_create_bucket_for_streaming
)


@pytest.fixture
def glue_component_with_connector():
return GlueComponent(
name="test-connector",
args=GlueComponentArgs(
jobs=[
GlueJobDefinition(
name="job-with-connector",
description="job with connector",
),
],
connector_config=ConnectorConfig(
vpc_id="vpc-12345678",
subnet_id="subnet-12345678",
security_groups=["sg-12345678"],
connection_properties={"BootstrapServers": "localhost:9092"},
),
),
)


@pulumi.runtime.test
def test_connection_creation(glue_component_with_connector):

def should_have_one(connections: list[aws.glue.Connection]):
assert len(connections) == 1

pulumi.Output.all(glue_component_with_connector.connection).apply(should_have_one)

0 comments on commit e5730f8

Please sign in to comment.