mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 09:22:49 -05:00
* chore(dynamodb): vendor the input shapes of botocore's DynamoDB model tools/aws/regen_dynamodb_shapes.py keeps each operation's input shape and the type of every shape it reaches, from the pinned botocore release. make aws-data-sync regenerates it and make aws-data-check keeps it in sync. * fix(dynamodb): reject a request member of the wrong JSON type DynamoDB answers a member of the wrong JSON type with a SerializationException before it runs the operation, such as "NUMBER_VALUE cannot be converted to String" for a number BillingMode or IndexName. The message names the JSON token and the Java type, or says "Unexpected field type", "Unexpected value type in payload", "Start of structure or map found where not expected" or "UnknownError" by where the value sits. The first bad member in body order is reported. A JSON null counts as absent and an unknown member is ignored. Floci now checks every DynamoDB JSON request against the vendored input shapes. A number in an ExclusiveStartKey S value is one of these errors on AWS, so that test now expects the SerializationException. * fix(dynamodb): keep provenance out of the shapes freshness check The shapes file now carries its provenance in a _source block, like the other vendored AWS data, and --check compares it without that block. A run against --botocore-data or a local checkout no longer reports the file as stale when only the botocore label differs.
73 lines
3.1 KiB
Python
73 lines
3.1 KiB
Python
"""Tests for regen_dynamodb_shapes.
|
|
|
|
Run with: pytest tools/aws -q (or: make aws-data-test)
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import regen_dynamodb_shapes as r
|
|
|
|
|
|
MODEL = {
|
|
"operations": {
|
|
"Scan": {"input": {"shape": "ScanInput"}, "output": {"shape": "ScanOutput"}},
|
|
"DescribeLimits": {"input": {"shape": "DescribeLimitsInput"}},
|
|
"NoInput": {},
|
|
},
|
|
"shapes": {
|
|
"ScanInput": {"type": "structure", "members": {
|
|
"TableName": {"shape": "TableName"},
|
|
"AttributesToGet": {"shape": "AttributeNameList"},
|
|
"ExclusiveStartKey": {"shape": "Key"},
|
|
}},
|
|
"ScanOutput": {"type": "structure", "members": {"Count": {"shape": "Integer"}}},
|
|
"DescribeLimitsInput": {"type": "structure", "members": {}},
|
|
"TableName": {"type": "string", "min": 3},
|
|
"AttributeNameList": {"type": "list", "member": {"shape": "AttributeName"}},
|
|
"AttributeName": {"type": "string"},
|
|
"Key": {"type": "map", "key": {"shape": "AttributeName"}, "value": {"shape": "AttributeValue"}},
|
|
"AttributeValue": {"type": "structure", "members": {"S": {"shape": "AttributeName"}}},
|
|
"Integer": {"type": "integer"},
|
|
},
|
|
}
|
|
|
|
|
|
def test_keeps_only_input_shapes_and_their_types():
|
|
doc = r.build(MODEL, "botocore test")
|
|
|
|
assert doc["_source"] == {"generator": "tools/aws/regen_dynamodb_shapes.py", "botocore": "botocore test"}
|
|
assert doc["operations"] == {"DescribeLimits": "DescribeLimitsInput", "Scan": "ScanInput"}
|
|
assert "ScanOutput" not in doc["shapes"]
|
|
assert "Integer" not in doc["shapes"]
|
|
assert doc["shapes"]["ScanInput"] == {"type": "structure", "members": {
|
|
"TableName": "TableName", "AttributesToGet": "AttributeNameList", "ExclusiveStartKey": "Key"}}
|
|
assert doc["shapes"]["TableName"] == {"type": "string"}
|
|
assert doc["shapes"]["AttributeNameList"] == {"type": "list", "member": "AttributeName"}
|
|
assert doc["shapes"]["Key"] == {"type": "map", "value": "AttributeValue"}
|
|
|
|
|
|
def test_check_ignores_provenance(tmp_path, monkeypatch):
|
|
output = tmp_path / "shapes.json"
|
|
output.write_text(r.render(r.build(MODEL, "botocore 0.0.1 (local/aws/botocore)")), encoding="utf-8")
|
|
monkeypatch.setattr(r, "resolve_botocore_data", lambda explicit: (tmp_path, "--botocore-data /elsewhere"))
|
|
monkeypatch.setattr(r, "load_model", lambda data: MODEL)
|
|
|
|
assert r.main(["--check", "--output", str(output)]) == 0
|
|
|
|
|
|
def test_check_reports_changed_shapes(tmp_path, monkeypatch):
|
|
output = tmp_path / "shapes.json"
|
|
changed = {**MODEL, "shapes": {**MODEL["shapes"], "TableName": {"type": "integer"}}}
|
|
output.write_text(r.render(r.build(changed, "botocore test")), encoding="utf-8")
|
|
monkeypatch.setattr(r, "resolve_botocore_data", lambda explicit: (tmp_path, "botocore test"))
|
|
monkeypatch.setattr(r, "load_model", lambda data: MODEL)
|
|
|
|
assert r.main(["--check", "--output", str(output)]) == 1
|
|
|
|
|
|
def test_output_is_stable():
|
|
first = r.render(r.build(MODEL, "botocore test"))
|
|
second = r.render(r.build(MODEL, "botocore test"))
|
|
|
|
assert first == second
|
|
assert first.endswith("\n")
|