Skip to content

Commit d2e762b

Browse files
committed
add test functions. refactor and add more tests. not aot yet.
1 parent 9eb5298 commit d2e762b

File tree

5 files changed

+311
-63
lines changed

5 files changed

+311
-63
lines changed

libraries/tests/e2e/functions/idempotency/Function/src/Function/Function.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,50 @@ public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest apigwProxy
2424
}
2525
}
2626

27+
namespace IdempotencyAttributeTest
28+
{
29+
public class Function
30+
{
31+
public Function()
32+
{
33+
var tableName = Environment.GetEnvironmentVariable("IDEMPOTENCY_TABLE_NAME");
34+
Idempotency.Configure(builder => builder.UseDynamoDb(tableName));
35+
}
36+
37+
public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest apigwProxyEvent, ILambdaContext context)
38+
{
39+
return new APIGatewayProxyResponse
40+
{
41+
Body = MyInternalMethod("dummy", apigwProxyEvent.RequestContext.RequestId),
42+
StatusCode = 200
43+
};
44+
}
45+
46+
[Idempotent]
47+
private string MyInternalMethod(string argOne, [IdempotencyKey] string argTwo) {
48+
return Guid.NewGuid().ToString();
49+
}
50+
}
51+
}
2752

28-
namespace Function2
53+
namespace IdempotencyPayloadSubsetTest
2954
{
3055
public class Function
3156
{
3257
public Function()
3358
{
34-
// var tableName = Environment.GetEnvironmentVariable("IDEMPOTENCY_TABLE_NAME");
35-
// Idempotency.Configure(builder => builder.UseDynamoDb(tableName));
59+
var tableName = Environment.GetEnvironmentVariable("IDEMPOTENCY_TABLE_NAME");
60+
Idempotency.Configure(builder =>
61+
builder
62+
.WithOptions(optionsBuilder =>
63+
optionsBuilder.WithEventKeyJmesPath("powertools_json(Body).[\"user_id\", \"product_id\"]"))
64+
.UseDynamoDb(tableName));
3665
}
3766

38-
// [Idempotent]
39-
public string FunctionHandler(APIGatewayProxyRequest apigwProxyEvent, ILambdaContext context)
67+
[Idempotent]
68+
public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest apigwProxyEvent, ILambdaContext context)
4069
{
41-
return "Hello, World!";
70+
return TestHelper.TestMethod(apigwProxyEvent);
4271
}
4372
}
4473
}

libraries/tests/e2e/functions/idempotency/Function/src/Function/TestHelper.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ public static class TestHelper
77
{
88
public static APIGatewayProxyResponse TestMethod(APIGatewayProxyRequest apigwProxyEvent)
99
{
10-
var requestContextRequestId = apigwProxyEvent.RequestContext.RequestId;
1110
var response = new
1211
{
13-
RequestId = requestContextRequestId,
1412
Greeting = "Hello Powertools for AWS Lambda (.NET)",
15-
MethodGuid = GenerateGuid(), // Guid generated by the GenerateGuid method. used to compare Method output
16-
HandlerGuid = Guid.NewGuid().ToString() // Guid generated in the Handler. used to compare Handler output
13+
Guid = Guid.NewGuid().ToString() // Guid generated in the Handler. used to compare Handler output
1714
};
1815

1916
try
@@ -35,13 +32,4 @@ public static APIGatewayProxyResponse TestMethod(APIGatewayProxyRequest apigwPro
3532
};
3633
}
3734
}
38-
39-
/// <summary>
40-
/// Generates a new Guid to check if value is the same between calls (should be when idempotency enabled)
41-
/// </summary>
42-
/// <returns>GUID</returns>
43-
private static string GenerateGuid()
44-
{
45-
return Guid.NewGuid().ToString();
46-
}
4735
}

0 commit comments

Comments
 (0)