Skip to content

Commit 11c62bd

Browse files
committed
Metrics test for execution context
1 parent 49f05e4 commit 11c62bd

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using AWS.Lambda.Powertools.Common;
2+
using Moq;
3+
using Xunit;
4+
5+
namespace AWS.Lambda.Powertools.Metrics.Tests;
6+
7+
[Collection("Sequential")]
8+
public class MetricsTests
9+
{
10+
[Fact]
11+
public void Metrics_Set_Execution_Environment_Context()
12+
{
13+
// Arrange
14+
var assemblyName = "AWS.Lambda.Powertools.Metrics";
15+
var assemblyVersion = "1.0.0";
16+
17+
var env = new Mock<IPowertoolsEnvironment>();
18+
env.Setup(x => x.GetAssemblyName(It.IsAny<Metrics>())).Returns(assemblyName);
19+
env.Setup(x => x.GetAssemblyVersion(It.IsAny<Metrics>())).Returns(assemblyVersion);
20+
21+
var conf = new PowertoolsConfigurations(new SystemWrapper(env.Object));
22+
23+
var metrics = new Metrics(conf);
24+
25+
// Assert
26+
env.Verify(v =>
27+
v.SetEnvironmentVariable(
28+
"AWS_EXECUTION_ENV", $"PTFeature/Metrics/{assemblyVersion}"
29+
), Times.Once);
30+
31+
env.Verify(v =>
32+
v.GetEnvironmentVariable(
33+
"AWS_EXECUTION_ENV"
34+
), Times.Once);
35+
}
36+
}

0 commit comments

Comments
 (0)