-
Notifications
You must be signed in to change notification settings - Fork 467
Expand file tree
/
Copy pathUtilitiesTests.cs
More file actions
101 lines (90 loc) · 4.55 KB
/
UtilitiesTests.cs
File metadata and controls
101 lines (90 loc) · 4.55 KB
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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using Microsoft.Azure.WebJobs.Script.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Xunit;
namespace Azure.Functions.Cli.UnitTests.HelperTests
{
public class UtilitiesTests
{
[Theory]
[InlineData(LogLevel.None)]
[InlineData(LogLevel.Debug)]
[InlineData(LogLevel.Information)]
public void GetHostJsonDefaultLogLevel_Test(LogLevel expectedLogLevel)
{
var settings = new Dictionary<string, string>();
settings.Add(ConfigurationPath.Combine(ConfigurationSectionNames.JobHost, "logging", "loglevel", "default"), expectedLogLevel.ToString());
var testConfiguration = TestUtilities.CreateSetupWithConfiguration(settings);
LogLevel actualLogLevel;
bool result = Utilities.LogLevelExists(testConfiguration, Utilities.LogLevelDefaultSection, out actualLogLevel);
Assert.Equal(actualLogLevel, expectedLogLevel);
}
[Theory]
[InlineData("ExtensionBundle", true)]
[InlineData("extensionBundle", false)]
public void JobHostConfigSectionExists_Test(string section, bool expected)
{
var settings = new Dictionary<string, string>();
if (expected)
{
settings.Add(ConfigurationPath.Combine(ConfigurationSectionNames.JobHost, "extensionBundle", "id"), "Microsoft.Azure.Functions.ExtensionBundle");
settings.Add(ConfigurationPath.Combine(ConfigurationSectionNames.JobHost, "extensionBundle", "version"), "[2.*, 3.0.0)");
}
var testConfiguration = TestUtilities.CreateSetupWithConfiguration(settings);
Assert.Equal(expected, Utilities.JobHostConfigSectionExists(testConfiguration, section));
}
[Theory]
[InlineData("Function.Function1", LogLevel.None, true)]
[InlineData("Function.Function1", LogLevel.Warning, true)]
[InlineData("Function.Function1.User", LogLevel.Information, true)]
[InlineData("Host.General", LogLevel.Information, false)]
[InlineData("Host.Startup", LogLevel.Error, true)]
[InlineData("Host.General", LogLevel.Warning, true)]
public void DefaultLoggingFilter_Test(string inputCategory, LogLevel inputLogLevel, bool expected)
{
Assert.Equal(expected, Utilities.DefaultLoggingFilter(inputCategory, inputLogLevel, LogLevel.Information, LogLevel.Warning));
}
[Theory]
[InlineData("Function.Function1", true)]
[InlineData("Random", false)]
[InlineData("Host.Startup", true)]
[InlineData("Microsoft.Azure.WebJobs.TestLogger", true)]
[InlineData("Microsoft.Azure.TestLogger", false)]
public void IsSystemLogCategory_Test(string inputCategory, bool expected)
{
Assert.Equal(expected, Utilities.IsSystemLogCategory(inputCategory));
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Test_IsMinifiedVersion(bool expected)
{
var filePath = Path.Combine("artifactsconfig.json");
string artifactsJsonContent = "{\"minifiedVersion\": " + expected.ToString().ToLower() + "}";
File.WriteAllTextAsync(filePath, artifactsJsonContent).GetAwaiter().GetResult();
bool output = Utilities.IsMinifiedVersion();
File.Delete(filePath);
Assert.Equal(expected, output);
}
[Theory]
[InlineData(null, null)]
[InlineData("", null)]
[InlineData(";", null)]
[InlineData("InstrumentationKey=abc123;", "abc123")]
[InlineData("InstrumentationKey=abc123;IngestionEndpoint=https://...", "abc123")]
[InlineData(" InstrumentationKey = abc123 ;", "abc123")]
[InlineData("InstrumentationKey=abc123;OtherKey=xyz", "abc123")]
[InlineData("otherKey=xyz;InstrumentationKey=abc123;", "abc123")]
[InlineData("InstrumentationKey=ABC123", "ABC123")]
[InlineData("instrumentationkey=abc123", "abc123")]
[InlineData("InstrumentationKey= ;", null)]
[InlineData("SomeKey=SomeValue;AnotherKey=AnotherValue", null)]
public void ExtractIKeyFromConnectionString_ReturnsExpectedInstrumentationKey(string connectionString, string expected)
{
var actual = Utilities.ExtractIKeyFromConnectionString(connectionString);
Assert.Equal(expected, actual);
}
}
}