- Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathEdgeCaseTests.cs
108 lines (91 loc) · 3.96 KB
/
EdgeCaseTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
usingSystem.Net;
usingAmazon.Lambda.APIGatewayEvents;
usingAmazon.Lambda.Core;
usingAmazon.Lambda.RuntimeSupport;
usingAmazon.Lambda.Serialization.SystemTextJson;
usingAmazon.Lambda.TestTool.Models;
usingAmazon.Lambda.TestTool.Tests.Common.Retries;
usingXunit;
usingXunit.Abstractions;
namespaceAmazon.Lambda.TestTool.IntegrationTests;
[Collection("ApiGatewayTests")]
publicclassEdgeCaseTests:BaseApiGatewayTest
{
publicEdgeCaseTests(ITestOutputHelpertestOutputHelper):base(testOutputHelper)
{
}
[RetryFact]
publicasyncTaskTestLambdaReturnString()
{
varports=GetFreePorts();
varlambdaPort=ports.lambdaPort;
varapiGatewayPort=ports.apiGatewayPort;
CancellationTokenSource=newCancellationTokenSource();
CancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(120));
varconsoleError=Console.Error;
try
{
Console.SetError(TextWriter.Null);
awaitStartTestToolProcessAsync(ApiGatewayEmulatorMode.HttpV2,"stringfunction",lambdaPort,apiGatewayPort,CancellationTokenSource);
awaitWaitForGatewayHealthCheck(apiGatewayPort);
varhandler=(APIGatewayHttpApiV2ProxyRequestrequest,ILambdaContextcontext)=>
{
TestOutputHelper.WriteLine($"TestLambdaReturnString");
returnrequest.Body.ToUpper();
};
_=LambdaBootstrapBuilder.Create(handler,newDefaultLambdaJsonSerializer())
.ConfigureOptions(x =>x.RuntimeApiEndpoint=$"localhost:{lambdaPort}/stringfunction")
.Build()
.RunAsync(CancellationTokenSource.Token);
varresponse=awaitTestEndpoint("stringfunction",apiGatewayPort);
varresponseContent=awaitresponse.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK,response.StatusCode);
Assert.Equal("HELLO WORLD",responseContent);
}
finally
{
awaitCancellationTokenSource.CancelAsync();
Console.SetError(consoleError);
}
}
[RetryFact]
publicasyncTaskTestLambdaWithNullEndpoint()
{
varports=GetFreePorts();
varlambdaPort=ports.lambdaPort;
varapiGatewayPort=ports.apiGatewayPort;
CancellationTokenSource=newCancellationTokenSource();
CancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(120));
varconsoleError=Console.Error;
try
{
Console.SetError(TextWriter.Null);
awaitStartTestToolProcessWithNullEndpoint(ApiGatewayEmulatorMode.HttpV2,"testfunction",lambdaPort,apiGatewayPort,CancellationTokenSource);
awaitWaitForGatewayHealthCheck(apiGatewayPort);
varhandler=(APIGatewayHttpApiV2ProxyRequestrequest,ILambdaContextcontext)=>
{
TestOutputHelper.WriteLine($"TestLambdaWithNullEndpoint");
returnnewAPIGatewayHttpApiV2ProxyResponse
{
StatusCode=200,
Body=request.Body.ToUpper()
};
};
_=LambdaBootstrapBuilder.Create(handler,newDefaultLambdaJsonSerializer())
.ConfigureOptions(x =>x.RuntimeApiEndpoint=$"localhost:{lambdaPort}/testfunction")
.Build()
.RunAsync(CancellationTokenSource.Token);
varresponse=awaitTestEndpoint("testfunction",apiGatewayPort);
varresponseContent=awaitresponse.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK,response.StatusCode);
Assert.Equal("HELLO WORLD",responseContent);
}
finally
{
awaitCancellationTokenSource.CancelAsync();
Console.SetError(consoleError);
}
}
}