|
13 | 13 | using NewRelic.Testing.Assertions;
|
14 | 14 | using NUnit.Framework;
|
15 | 15 | using Telerik.JustMock;
|
| 16 | +using Telerik.JustMock.Expectations.Abstraction; |
16 | 17 | using Telerik.JustMock.Helpers;
|
17 | 18 |
|
18 | 19 | namespace NewRelic.Agent.Core.Configuration.UnitTest
|
@@ -2069,7 +2070,92 @@ public void ApplicationNamesPullsNameFromProcessIdIfAppDomainAppVirtualPathIsNul
|
2069 | 2070 | );
|
2070 | 2071 | }
|
2071 | 2072 |
|
| 2073 | + [Test] |
| 2074 | + public void ApplicationNamesUsesLambdaFunctionNameIfBlank() |
| 2075 | + { |
| 2076 | + _runTimeConfig.ApplicationNames = new List<string>(); |
| 2077 | + |
| 2078 | + Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); |
| 2079 | + Mock.Arrange(() => _bootstrapConfiguration.ServerlessFunctionName).Returns("MyFunc"); |
| 2080 | + Mock.Arrange(() => _bootstrapConfiguration.ServerlessFunctionVersion).Returns("2"); |
| 2081 | + //Sets to default return null for all calls unless overriden by later arrange. |
| 2082 | + Mock.Arrange(() => _environment.GetEnvironmentVariable(Arg.IsAny<string>())).Returns<string>(null); |
| 2083 | + |
| 2084 | + Mock.Arrange(() => _configurationManagerStatic.GetAppSetting(Constants.AppSettingsAppName)).Returns<string>(null); |
| 2085 | + |
| 2086 | + _localConfig.application.name = new List<string>(); |
| 2087 | + |
| 2088 | + NrAssert.Multiple( |
| 2089 | + () => Assert.That(_defaultConfig.ApplicationNames.Count(), Is.EqualTo(1)), |
| 2090 | + () => Assert.That(_defaultConfig.ApplicationNames.FirstOrDefault(), Is.EqualTo("MyFunc")), |
| 2091 | + () => Assert.That(_defaultConfig.ServerlessFunctionVersion, Is.EqualTo("2")), |
| 2092 | + () => Assert.That(_defaultConfig.ApplicationNamesSource, Is.EqualTo("Environment Variable (AWS_LAMBDA_FUNCTION_NAME)")) |
| 2093 | + ); |
| 2094 | + } |
| 2095 | + |
| 2096 | + [Test] |
| 2097 | + public void ApplicationNamesUsesLambdaFunctionNameIfDefault() |
| 2098 | + { |
| 2099 | + _runTimeConfig.ApplicationNames = new List<string>(); |
| 2100 | + |
| 2101 | + Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); |
| 2102 | + Mock.Arrange(() => _bootstrapConfiguration.ServerlessFunctionName).Returns("MyFunc"); |
| 2103 | + //Sets to default return null for all calls unless overriden by later arrange. |
| 2104 | + Mock.Arrange(() => _environment.GetEnvironmentVariable(Arg.IsAny<string>())).Returns<string>(null); |
| 2105 | + |
| 2106 | + Mock.Arrange(() => _configurationManagerStatic.GetAppSetting(Constants.AppSettingsAppName)).Returns<string>(null); |
| 2107 | + |
| 2108 | + _localConfig.application.name = new List<string> { "My Application" }; |
| 2109 | + |
| 2110 | + NrAssert.Multiple( |
| 2111 | + () => Assert.That(_defaultConfig.ApplicationNames.Count(), Is.EqualTo(1)), |
| 2112 | + () => Assert.That(_defaultConfig.ApplicationNames.FirstOrDefault(), Is.EqualTo("MyFunc")), |
| 2113 | + () => Assert.That(_defaultConfig.ApplicationNamesSource, Is.EqualTo("Environment Variable (AWS_LAMBDA_FUNCTION_NAME)")) |
| 2114 | + ); |
| 2115 | + } |
2072 | 2116 |
|
| 2117 | + [Test] |
| 2118 | + public void ApplicationNamesDoesNotUseLambdaFunctionNameIfEnvVarSet() |
| 2119 | + { |
| 2120 | + _runTimeConfig.ApplicationNames = new List<string>(); |
| 2121 | + |
| 2122 | + Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); |
| 2123 | + Mock.Arrange(() => _bootstrapConfiguration.ServerlessFunctionName).Returns("MyFunc"); |
| 2124 | + //Sets to default return null for all calls unless overriden by later arrange. |
| 2125 | + Mock.Arrange(() => _environment.GetEnvironmentVariable(Arg.IsAny<string>())).Returns<string>(null); |
| 2126 | + Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_APP_NAME")).Returns("My App Name"); |
| 2127 | + |
| 2128 | + Mock.Arrange(() => _configurationManagerStatic.GetAppSetting(Constants.AppSettingsAppName)).Returns<string>(null); |
| 2129 | + |
| 2130 | + _localConfig.application.name = new List<string> { "My Application" }; |
| 2131 | + |
| 2132 | + NrAssert.Multiple( |
| 2133 | + () => Assert.That(_defaultConfig.ApplicationNames.Count(), Is.EqualTo(1)), |
| 2134 | + () => Assert.That(_defaultConfig.ApplicationNames.FirstOrDefault(), Is.EqualTo("My App Name")), |
| 2135 | + () => Assert.That(_defaultConfig.ApplicationNamesSource, Is.EqualTo("Environment Variable (NEW_RELIC_APP_NAME)")) |
| 2136 | + ); |
| 2137 | + } |
| 2138 | + |
| 2139 | + [Test] |
| 2140 | + public void ApplicationNamesDoesNotUseLambdaFunctionNameIfBlank() |
| 2141 | + { |
| 2142 | + _runTimeConfig.ApplicationNames = new List<string>(); |
| 2143 | + |
| 2144 | + Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); |
| 2145 | + Mock.Arrange(() => _bootstrapConfiguration.ServerlessFunctionName).Returns(""); |
| 2146 | + //Sets to default return null for all calls unless overriden by later arrange. |
| 2147 | + Mock.Arrange(() => _environment.GetEnvironmentVariable(Arg.IsAny<string>())).Returns<string>(null); |
| 2148 | + |
| 2149 | + Mock.Arrange(() => _configurationManagerStatic.GetAppSetting(Constants.AppSettingsAppName)).Returns<string>(null); |
| 2150 | + |
| 2151 | + _localConfig.application.name = new List<string> { "My Application" }; |
| 2152 | + |
| 2153 | + NrAssert.Multiple( |
| 2154 | + () => Assert.That(_defaultConfig.ApplicationNames.Count(), Is.EqualTo(1)), |
| 2155 | + () => Assert.That(_defaultConfig.ApplicationNames.FirstOrDefault(), Is.EqualTo("My Application")), |
| 2156 | + () => Assert.That(_defaultConfig.ApplicationNamesSource, Is.EqualTo("NewRelic Config")) |
| 2157 | + ); |
| 2158 | + } |
2073 | 2159 | #endregion ApplicationNames
|
2074 | 2160 |
|
2075 | 2161 |
|
|
0 commit comments