-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_cfn_inputs.py
57 lines (45 loc) · 1.47 KB
/
test_cfn_inputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import boto3
import json
import logging
from pathlib import Path
import plastic_yellow_bird as pyb
import pytest
logging.basicConfig()
logger = logging.getLogger()
from app import app
from stacks.control_broker_stack import ControlBrokerStack
@pytest.fixture
def outer_state_machine_arn(stack: ControlBrokerStack):
return stack.sfn_outer_eval_engine.attr_arn
@pytest.fixture
def valid_template_json():
return (
Path(__file__).parent / "supplementary_files/valid_template.json"
).read_text()
@pyb.test
def test_valid_cfn_template_passes_control_broker_evaluation(
outer_state_machine_arn, valid_template_json
):
sfn = boto3.client("stepfunctions")
r = sfn.start_sync_execution(
stateMachineArn=outer_state_machine_arn,
input=json.dumps({"CFN": [valid_template_json]}),
)
logger.debug("Full result: %s", r)
if r["status"] in ["FAILED", "TIMED_OUT"]:
raise Exception("Sync start failed")
outer_sfn_exec_id = r["executionArn"]
output = json.loads(r["output"])
nested_results = output["ForEachTemplate"]
results = [
{
"Status": i.get("TemplateToNestedSFN").get("Status"),
"Cause": i.get("TemplateToNestedSFN").get("Cause"),
"EvalResultsTablePk": outer_sfn_exec_id,
}
for i in nested_results
]
logger.debug("Parsed results: %s", results)
assert all(
i["Status"] == "SUCCEEDED" for i in results
), "A valid template had infractions"