Skip to content

Commit 75ad2af

Browse files
auto commit
1 parent 252d053 commit 75ad2af

File tree

6 files changed

+44
-50
lines changed

6 files changed

+44
-50
lines changed

Examples/runtimes/net/src/TestUtils.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Collections.Generic;
34
using Amazon.DynamoDBv2.Model;
45

56
public class TestUtils
@@ -84,4 +85,21 @@ public static void PrintAttributeValue(AttributeValue value)
8485
if (value.IsBOOLSet) Console.Write($"BOOL {value.BOOL}\n");
8586
Console.Write("UNKNOWN\n");
8687
}
88+
89+
// Helper method to clean up test items
90+
public static async System.Threading.Tasks.Task CleanupItems(string tableName, string partitionKey, string sortKey)
91+
{
92+
var ddb = new Amazon.DynamoDBv2.AmazonDynamoDBClient();
93+
var key = new Dictionary<string, AttributeValue>
94+
{
95+
["partition_key"] = new AttributeValue { S = partitionKey },
96+
["sort_key"] = new AttributeValue { N = sortKey }
97+
};
98+
var deleteRequest = new DeleteItemRequest
99+
{
100+
TableName = tableName,
101+
Key = key
102+
};
103+
await ddb.DeleteItemAsync(deleteRequest);
104+
}
87105
}

Examples/runtimes/net/src/migration/PlaintextToAWSDBE/MigrationUtils.cs

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@ public class MigrationUtils
1616
public static readonly string DO_NOTHING_VALUE = "this will never be encrypted nor signed";
1717

1818
// Verify that a returned item matches the expected values
19-
public static bool VerifyReturnedItem(GetItemResponse response, string partitionKeyValue, string sortKeyValue,
20-
string encryptedAndSignedValue = null, string signOnlyValue = null, string doNothingValue = null)
21-
{
22-
// Use default values if not provided
23-
encryptedAndSignedValue = encryptedAndSignedValue ?? ENCRYPTED_AND_SIGNED_VALUE;
24-
signOnlyValue = signOnlyValue ?? SIGN_ONLY_VALUE;
25-
doNothingValue = doNothingValue ?? DO_NOTHING_VALUE;
26-
19+
public static bool VerifyReturnedItem(GetItemResponse response, string partitionKeyValue, string sortKeyValue)
20+
{
2721
var item = response.Item;
2822

2923
// Verify partition key
@@ -39,55 +33,24 @@ public static bool VerifyReturnedItem(GetItemResponse response, string partition
3933
}
4034

4135
// Verify attribute1 (will be encrypted and signed in future steps)
42-
if (!item.ContainsKey("attribute1") || item["attribute1"].S != encryptedAndSignedValue)
36+
if (!item.ContainsKey("attribute1") || item["attribute1"].S != ENCRYPTED_AND_SIGNED_VALUE)
4337
{
44-
throw new Exception($"attribute1 mismatch: expected {encryptedAndSignedValue}, got {(item.ContainsKey("attribute1") ? item["attribute1"].S : "null")}");
38+
throw new Exception($"attribute1 mismatch: expected {ENCRYPTED_AND_SIGNED_VALUE}, got {(item.ContainsKey("attribute1") ? item["attribute1"].S : "null")}");
4539
}
4640

4741
// Verify attribute2 (will be signed but not encrypted in future steps)
48-
if (!item.ContainsKey("attribute2") || item["attribute2"].S != signOnlyValue)
42+
if (!item.ContainsKey("attribute2") || item["attribute2"].S != SIGN_ONLY_VALUE)
4943
{
50-
throw new Exception($"attribute2 mismatch: expected {signOnlyValue}, got {(item.ContainsKey("attribute2") ? item["attribute2"].S : "null")}");
44+
throw new Exception($"attribute2 mismatch: expected {SIGN_ONLY_VALUE}, got {(item.ContainsKey("attribute2") ? item["attribute2"].S : "null")}");
5145
}
5246

5347
// Verify attribute3 (will neither be encrypted nor signed in future steps)
54-
if (!item.ContainsKey("attribute3") || item["attribute3"].S != doNothingValue)
48+
if (!item.ContainsKey("attribute3") || item["attribute3"].S != DO_NOTHING_VALUE)
5549
{
56-
throw new Exception($"attribute3 mismatch: expected {doNothingValue}, got {(item.ContainsKey("attribute3") ? item["attribute3"].S : "null")}");
50+
throw new Exception($"attribute3 mismatch: expected {DO_NOTHING_VALUE}, got {(item.ContainsKey("attribute3") ? item["attribute3"].S : "null")}");
5751
}
5852

5953
return true;
6054
}
61-
62-
// Helper method to clean up test items
63-
public static async System.Threading.Tasks.Task CleanupItems(string tableName, string partitionKey, string[] sortKeys)
64-
{
65-
var ddb = new Amazon.DynamoDBv2.AmazonDynamoDBClient();
66-
67-
foreach (var sortKey in sortKeys)
68-
{
69-
try
70-
{
71-
var key = new Dictionary<string, AttributeValue>
72-
{
73-
["partition_key"] = new AttributeValue { S = partitionKey },
74-
["sort_key"] = new AttributeValue { N = sortKey }
75-
};
76-
77-
var deleteRequest = new DeleteItemRequest
78-
{
79-
TableName = tableName,
80-
Key = key
81-
};
82-
83-
await ddb.DeleteItemAsync(deleteRequest);
84-
}
85-
catch (Exception e)
86-
{
87-
// Log but don't fail if cleanup fails
88-
Console.WriteLine($"Warning: Failed to clean up test item with sort key {sortKey}: {e.Message}");
89-
}
90-
}
91-
}
9255
}
9356
}

Examples/runtimes/net/src/migration/PlaintextToAWSDBE/awsdbe/MigrationStep1Test.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ public async Task TestMigrationStep1()
6767
Assert.True(success, "MigrationStep1 should be able to read items written by Step 3");
6868

6969
// Cleanup
70-
await MigrationUtils.CleanupItems(tableName, partitionKey, sortKeys);
70+
foreach (var sortKey in sortKeys)
71+
{
72+
await TestUtils.CleanupItems(tableName, partitionKey, sortKey);
73+
}
7174
}
7275
}
7376
}

Examples/runtimes/net/src/migration/PlaintextToAWSDBE/awsdbe/MigrationStep2Test.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ public async Task TestMigrationStep2()
6767
Assert.True(success, "MigrationStep2 should be able to read items written by Step 3");
6868

6969
// Cleanup
70-
await MigrationUtils.CleanupItems(tableName, partitionKey, sortKeys);
70+
foreach (var sortKey in sortKeys)
71+
{
72+
await TestUtils.CleanupItems(tableName, partitionKey, sortKey);
73+
}
7174
}
7275
}
7376
}

Examples/runtimes/net/src/migration/PlaintextToAWSDBE/awsdbe/MigrationStep3Test.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ public async Task TestMigrationStep3()
7171
Assert.True(success, "MigrationStep3 should be able to read items written by Step 2");
7272

7373
// Cleanup
74-
await MigrationUtils.CleanupItems(tableName, partitionKey, sortKeys);
74+
foreach (var sortKey in sortKeys)
75+
{
76+
await TestUtils.CleanupItems(tableName, partitionKey, sortKey);
77+
}
7578
}
7679
}
7780
}

Examples/runtimes/net/src/migration/PlaintextToAWSDBE/plaintext/MigrationStep0Test.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ public async Task TestMigrationStep0()
6262
exception = await Assert.ThrowsAsync<Exception>(() =>
6363
MigrationStep0.MigrationStep0Example(tableName, partitionKey, sortKeys[0], sortKeys[3]));
6464
Assert.Contains("attribute1 mismatch", exception.Message);
65-
66-
await MigrationUtils.CleanupItems(tableName, partitionKey, sortKeys);
65+
66+
// Cleanup
67+
foreach (var sortKey in sortKeys)
68+
{
69+
await TestUtils.CleanupItems(tableName, partitionKey, sortKey);
70+
}
6771
}
6872
}
6973
}

0 commit comments

Comments
 (0)