test/alternator: test invalid key types for GSI

This patch adds a test that types which are not allowed for GSI keys -
basically any type except S(tring), B(ytes) or N(number), are rejected
as expected - an error path that we didn't cover in existing tests.

The new test passes - Alternator doesn't have a bug in this area, and
as usual, also passes on DynamoDB.

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
This commit is contained in:
Nadav Har'El
2023-05-13 13:00:00 +03:00
parent c4021d0819
commit ad53d6a230

View File

@@ -1933,3 +1933,28 @@ def test_gsi_and_lsi_same_key(dynamodb):
KeyConditions={'p': {'AttributeValueList': [p], 'ComparisonOperator': 'EQ'}, 'x': {'AttributeValueList': [x], 'ComparisonOperator': 'EQ'}})
assert_index_query(table, 'gsi', [item],
KeyConditions={'x': {'AttributeValueList': [x], 'ComparisonOperator': 'EQ'}})
# Check that any type besides S(tring), B(ytes) or N(umber)s is *not* NOT
# allowed as the type of a GSI key attribute. We don't check here that these
# three types *are* allowed, because we already checked this in other tests
# (see test_gsi_6_*).
def test_gsi_invalid_key_types(dynamodb):
# The following are all the types that DynamoDB supports, as documented in
# https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.LowLevelAPI.html
# also the non-existent type "junk" yields the same error message.
for key_type in ['BOOL', 'NULL', 'M', 'L', 'SS', 'NS', 'BS', 'junk']:
# DynamDB's and Alternator's error messages are different, but both
# include the invalid type's name in single quotes.
with pytest.raises(ClientError, match=f"ValidationException.*'{key_type}'"):
with new_test_table(dynamodb,
KeySchema=[{ 'AttributeName': 'p', 'KeyType': 'HASH' }],
AttributeDefinitions=[
{ 'AttributeName': 'p', 'AttributeType': 'S' },
{ 'AttributeName': 'x', 'AttributeType': key_type },
],
GlobalSecondaryIndexes=[{
'IndexName': 'gsi',
'KeySchema': [{ 'AttributeName': 'x', 'KeyType': 'HASH' }],
'Projection': { 'ProjectionType': 'ALL' }
}]) as table:
pass