-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathDeployTest.cs
117 lines (99 loc) · 4.31 KB
/
DeployTest.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
109
110
111
112
113
114
115
116
117
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Amazon.Lambda;
using Amazon.Lambda.Model;
using Amazon.Lambda.Tools;
using Amazon.Lambda.Tools.Commands;
using Amazon.IdentityManagement;
using Amazon.IdentityManagement.Model;
namespace Amazon.Lambda.Tools.Test
{
public class DeployTest : IDisposable
{
const string LAMBDATOOL_TEST_ROLE = "lambdatools-test-role";
IAmazonIdentityManagementService _iamCient;
string _roleArn;
public DeployTest()
{
this._iamCient = new AmazonIdentityManagementServiceClient();
Task.Run(async () =>
{
try
{
this._roleArn = (await this._iamCient.GetRoleAsync(new GetRoleRequest { RoleName = LAMBDATOOL_TEST_ROLE })).Role.Arn;
}
catch (NoSuchEntityException)
{
// Role is not found so create a role with no permissions other then Lambda can assume the role.
// The role is deleted and reused in other runs of the test to make the test run faster.
this._roleArn = new RoleHelper(this._iamCient).CreateDefaultRole(LAMBDATOOL_TEST_ROLE, null);
}
}).Wait();
}
[Fact(Skip = "Turn off till accessible in prod")]
public async Task RunDeployCommand()
{
var fullPath = Path.GetFullPath("../TestFunction");
var command = new DeployFunctionCommand(new ConsoleToolLogger(), fullPath, new string[0]);
command.FunctionName = "test-function-" + DateTime.Now.Ticks;
command.Handler = "TestFunction::TestFunction.Function::ToUpper";
command.Timeout = 10;
command.MemorySize = 512;
command.Role = this._roleArn;
command.Runtime = "dotnetcore1.0";
var created = await command.ExecuteAsync();
try
{
Assert.True(created);
var invokeRequest = new InvokeRequest
{
FunctionName = command.FunctionName,
LogType = LogType.Tail,
Payload = "\"hello world\""
};
var response = await command.LambdaClient.InvokeAsync(invokeRequest);
var payload = new StreamReader(response.Payload).ReadToEnd();
var log = System.Text.UTF8Encoding.UTF8.GetString(Convert.FromBase64String(response.LogResult));
Assert.Equal("\"HELLO WORLD\"", payload);
}
finally
{
await command.LambdaClient.DeleteFunctionAsync(command.FunctionName);
}
}
[Fact]
public void ValidateCompatibleLambdaRuntimesAndTargetFrameworks()
{
// Validate that newer versions of the framework then what the current and possible future lambda runtimes throw an error.
Utilities.ValidateTargetFrameworkAndLambdaRuntime("dotnetcore1.0", "netcoreapp1.0");
Utilities.ValidateTargetFrameworkAndLambdaRuntime("dotnetcore1.1", "netcoreapp1.0");
Utilities.ValidateTargetFrameworkAndLambdaRuntime("dotnetcore1.1", "netcoreapp1.1");
Utilities.ValidateTargetFrameworkAndLambdaRuntime("dotnetcore2.0", "netcoreapp1.0");
Assert.Throws(typeof(LambdaToolsException), (() => Utilities.ValidateTargetFrameworkAndLambdaRuntime("dotnetcore1.0", "netcoreapp1.1")));
Assert.Throws(typeof(LambdaToolsException), (() => Utilities.ValidateTargetFrameworkAndLambdaRuntime("dotnetcore1.0", "netcoreapp2.0")));
Assert.Throws(typeof(LambdaToolsException), (() => Utilities.ValidateTargetFrameworkAndLambdaRuntime("dotnetcore1.1", "netcoreapp2.0")));
}
#region IDisposable Support
private bool disposedValue = false;
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
this._iamCient.Dispose();
}
disposedValue = true;
}
}
public void Dispose()
{
Dispose(true);
}
#endregion
}
}