Skip to content

Commit 4677513

Browse files
authored
feat: kinesis stream and functional test harness (#20)
1 parent fb74b5d commit 4677513

File tree

10 files changed

+380
-16
lines changed

10 files changed

+380
-16
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ jobs:
6161

6262
- name: Pytest
6363
shell: bash
64-
run: poetry run pytest -v tests
64+
run: poetry run pytest -v tests/unit

poetry.lock

Lines changed: 111 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jsonschema = "^3.2.0"
1818
[tool.poetry.dev-dependencies]
1919
pytest = "^6.2.4"
2020
black = "^21.7b0"
21+
pytest-terraform = { git = "https://github.com/cloud-custodian/pytest-terraform.git", branch = "work-dir-test-api" }
2122

2223
[build-system]
2324
requires = ["poetry-core>=1.0.0"]

tests/unit/conftest.py renamed to tests/conftest.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66
import pytest
77

88

9+
def load_data(filename, location="unit"):
10+
path = Path(__file__).parent / location / "data" / filename
11+
if not path.exists():
12+
return None
13+
with open(path) as f:
14+
return json.load(f)
15+
16+
17+
def write_data(filename, data, location="unit"):
18+
fpath = Path(__file__).parent / location / "data" / filename
19+
if not fpath.exists():
20+
fpath.write_text(data)
21+
22+
923
@pytest.fixture()
1024
def validate():
1125
def schema_validate(translator, resource):
@@ -15,9 +29,7 @@ def schema_validate(translator, resource):
1529
cfn = boto3.client("cloudformation")
1630
rtype = cfn.describe_type(TypeName=translator.cfn_type, Type="RESOURCE")
1731
schema = json.loads(rtype["Schema"])
18-
(Path(__file__).parent / "data" / schema_path).write_text(
19-
json.dumps(schema, indent=2)
20-
)
32+
write_data(schema_path, json.dumps(schema, indent=2))
2133

2234
props = set(resource)
2335
sprops = set(schema["properties"].keys())
@@ -40,11 +52,3 @@ def schema_validate(translator, resource):
4052
)
4153

4254
return schema_validate
43-
44-
45-
def load_data(filename):
46-
path = Path(__file__).parent / "data" / filename
47-
if not path.exists():
48-
return None
49-
with open(path) as f:
50-
return json.load(f)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
resource "random_pet" "name" {
2+
length = 2
3+
separator = "-"
4+
}
5+
6+
7+
resource "aws_kinesis_stream" "test_stream" {
8+
name = "test-${random_pet.name.id}"
9+
shard_count = 1
10+
retention_period = 48
11+
12+
shard_level_metrics = [
13+
"IncomingBytes",
14+
"OutgoingBytes",
15+
]
16+
17+
tags = {
18+
Environment = "test"
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import json
2+
3+
import conftest
4+
from pytest_terraform import terraform
5+
from tfdevops.cli import Translator, get_state_resources
6+
7+
8+
def get_state_path(tmpdir, tf_resources):
9+
with open(tmpdir / "state.json", "w") as fh:
10+
fh.write(json.dumps(tf_resources.terraform.show(), indent=2))
11+
return fh.name
12+
13+
14+
@terraform("aws_kinesis_stream")
15+
def test_kinesis_stream(tmpdir, aws_kinesis_stream, validate):
16+
resources = get_state_resources(None, get_state_path(tmpdir, aws_kinesis_stream))
17+
translator = Translator.get_translator("kinesis_stream")()
18+
props = translator.get_properties(resources["aws_kinesis_stream"][0])
19+
conftest.write_data(
20+
"kinesis_stream.json", json.dumps(resources["aws_kinesis_stream"][0], indent=2)
21+
)
22+
validate(translator, props)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"address": "aws_kinesis_stream.test_stream",
3+
"mode": "managed",
4+
"type": "aws_kinesis_stream",
5+
"name": "test_stream",
6+
"provider_name": "registry.terraform.io/hashicorp/aws",
7+
"schema_version": 1,
8+
"values": {
9+
"arn": "arn:aws:kinesis:us-east-2:112233445566:stream/test-poetic-marten",
10+
"encryption_type": "NONE",
11+
"enforce_consumer_deletion": false,
12+
"id": "arn:aws:kinesis:us-east-2:112233445566:stream/test-poetic-marten",
13+
"kms_key_id": "",
14+
"name": "test-poetic-marten",
15+
"retention_period": 48,
16+
"shard_count": 1,
17+
"shard_level_metrics": [
18+
"IncomingBytes",
19+
"OutgoingBytes"
20+
],
21+
"tags": {
22+
"Environment": "test"
23+
},
24+
"tags_all": {
25+
"Environment": "test"
26+
},
27+
"timeouts": null
28+
},
29+
"sensitive_values": {
30+
"shard_level_metrics": [
31+
false,
32+
false
33+
],
34+
"tags": {},
35+
"tags_all": {}
36+
},
37+
"depends_on": [
38+
"random_pet.name"
39+
]
40+
}

0 commit comments

Comments
 (0)