Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 83 additions & 5 deletions modules/tests/test_dynamodb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ fn main(log: String, _: LogSource) -> Result<(), i32> {
],
"binary_field": { "_binary": BASE64_STANDARD.encode("binary_data") } // Binary
});
let item_hm = serde_json::from_value::<HashMap<String, serde_json::Value>>(item_json).unwrap();
let item_hm = serde_json::from_value(item_json).unwrap();
let input = PutItemInput {
table_name: table_name.clone(),
item: item_hm,
// NONE - If ReturnValues is not specified, or if its value is NONE, then nothing is returned. (This setting is the default for ReturnValues.)
// ALL_OLD - If PutItem overwrote an attribute name-value pair, then the content of the old item is returned.
// https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html#DDB-PutItem-request-ReturnValues
return_values: Some(String::from("ALL_OLD")),
condition_expression: None,
expression_attribute_names: None,
Expand All @@ -56,8 +59,11 @@ fn main(log: String, _: LogSource) -> Result<(), i32> {
return Err(1);
}
Ok(output) => {
let output_json = to_value(&output).unwrap();
let expected = json!({"attributes":null});
let output_json =
to_value(&output).expect("failed deserializing PutItemOutput to value");
let expected = json!({
"attributes":null
});
plaid::print_debug_string(&format!("put_item output: {output_json}"));
if output_json != expected {
plaid::print_debug_string(&format!(
Expand All @@ -81,7 +87,44 @@ fn main(log: String, _: LogSource) -> Result<(), i32> {
};
let output = dynamodb::query(input).unwrap();
let output_json = to_value(&output).unwrap();
let expected = json!({"items":[{"age":33,"binaries":["ZGF0YTE=","ZGF0YTI="],"binary_field":{"_binary":"YmluYXJ5X2RhdGE="},"is_active":true,"metadata":{"city":"New York","country":"USA"},"name":"Jane Doe","null_field":null,"pk":"124","ratings":[3.8,4.5,5],"scores":[88,92,95],"tags":["aws","dev","rust"],"timestamp":"124"}]});
let expected = json!({
"items": [
{
"age": 33,
"binaries": [
"ZGF0YTE=",
"ZGF0YTI="
],
"binary_field": {
"_binary": "YmluYXJ5X2RhdGE="
},
"is_active": true,
"metadata": {
"city": "New York",
"country": "USA"
},
"name": "Jane Doe",
"null_field": null,
"pk": "124",
"ratings": [
3.8,
4.5,
5
],
"scores": [
88,
92,
95
],
"tags": [
"aws",
"dev",
"rust"
],
"timestamp": "124"
}
]
});
if output_json != expected {
plaid::print_debug_string(&format!(
"error: query output_json mismatch. expected {expected} got {output_json}"
Expand All @@ -107,7 +150,42 @@ fn main(log: String, _: LogSource) -> Result<(), i32> {

let output = dynamodb::delete_item(input).unwrap();
let output_json = to_value(&output).unwrap();
let expected = json!({"attributes":{"age":33,"binaries":["ZGF0YTE=","ZGF0YTI="],"binary_field":{"_binary":"YmluYXJ5X2RhdGE="},"is_active":true,"metadata":{"city":"New York","country":"USA"},"name":"Jane Doe","null_field":null,"pk":"124","ratings":[3.8,4.5,5],"scores":[88,92,95],"tags":["aws","dev","rust"],"timestamp":"124"}});
let expected = json!({
"attributes": {
"age": 33,
"binaries": [
"ZGF0YTE=",
"ZGF0YTI="
],
"binary_field": {
"_binary": "YmluYXJ5X2RhdGE="
},
"is_active": true,
"metadata": {
"city": "New York",
"country": "USA"
},
"name": "Jane Doe",
"null_field": null,
"pk": "124",
"ratings": [
3.8,
4.5,
5
],
"scores": [
88,
92,
95
],
"tags": [
"aws",
"dev",
"rust"
],
"timestamp": "124"
}
});
if output_json != expected {
plaid::print_debug_string(&format!(
"error: delete_item output_json mismatch. expected {expected} got {output_json}"
Expand Down
Loading