-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathNoUiStartupTests.cs
146 lines (120 loc) · 7.27 KB
/
NoUiStartupTests.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Xunit;
using Amazon.Lambda.TestTool;
namespace Amazon.Lambda.TestTool.Tests
{
public class NoUiStartupTests
{
[Fact]
public void DirectFunctionCallFromConfig()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "\"hello WORLD\"" }, runConfiguration);
Assert.Contains("HELLO WORLD", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void DirectFunctionCallNotFromConfig()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "\"hello WORLD\"", "--function-handler", "ToUpperFunc::ToUpperFunc.Function::ToLower" }, runConfiguration);
Assert.Contains("hello world", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void PayloadFromFile()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "payload-sample.json" }, runConfiguration);
Assert.Contains("HELLO FROM PAYLOAD FILE", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void ServerlessTemplateFunctionCall()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ServerlessTemplateExample");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "\"hello WORLD\"", "--function-handler", "ServerlessTemplateExample::ServerlessTemplateExample.Functions::HelloWorld" }, runConfiguration);
Assert.Contains("Hello World Test", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void ProjectHasMultipleLambdaFunctionsAndFunctionHandlerNotGiven()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ServerlessTemplateExample");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "\"hello WORLD\"" }, runConfiguration);
Assert.Contains("Project has more then one Lambda function defined. Use the --function-handler switch to identify the Lambda code to execute.", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void UseProfileAndRegionFromConfigFile()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "\"hello WORLD\"" }, runConfiguration);
Assert.Contains("HELLO WORLD", runConfiguration.OutputWriter.ToString());
Assert.Contains("Setting AWS_REGION environment variable to us-west-2.", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void UseExplicitRegion()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "\"hello WORLD\"", "--region", "fake-region" }, runConfiguration);
Assert.Contains("HELLO WORLD", runConfiguration.OutputWriter.ToString());
Assert.Contains("Setting AWS_REGION environment variable to fake-region.", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void NoProfileAndRegion()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("FunctionSignatureExamples");
// Profile is set to a nonexisting profile because if no profile is set on the command line or config file then the default profile will be set if it exists.
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--profile", "do-no-exist", "--payload", "\"hello WORLD\"", "--function-handler", "FunctionSignatureExamples::FunctionSignatureExamples.StaticMethods::TheStaticMethod" }, runConfiguration);
Assert.Contains("Warning: Profile do-no-exist not found in the aws credential store.", runConfiguration.OutputWriter.ToString());
Assert.Contains("No default AWS region configured. The --region switch can be used to configure an AWS Region.", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void DirectFunctionCallFromConfigWithDisableLogs()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "\"hello WORLD\"", "--disable-logs" }, runConfiguration);
Assert.Equal("\"HELLO WORLD\"", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void DirectFunctionCallNonDelimitedPayloadStringFromConfig()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "hello WORLD" }, runConfiguration);
Assert.Contains("HELLO WORLD", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void DirectFunctionCallSingleQuoteDelimitedPayloadStringFromConfig()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "'hello WORLD'" }, runConfiguration);
Assert.Contains("'HELLO WORLD'", runConfiguration.OutputWriter.ToString());
}
[Fact]
public void DirectFunctionCallIntegerPayloadFromConfig()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("IntegerFunc");
TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "42" }, runConfiguration);
Assert.Contains("Hello 42", runConfiguration.OutputWriter.ToString());
}
private TestToolStartup.RunConfiguration CreateRunConfiguration()
{
return new TestToolStartup.RunConfiguration
{
Mode = TestToolStartup.RunConfiguration.RunMode.Test,
OutputWriter = new StringWriter()
};
}
}
}