Skip to content

Commit 7a8cde1

Browse files
Fixing unit tests
1 parent 567780b commit 7a8cde1

File tree

8 files changed

+21
-15
lines changed

8 files changed

+21
-15
lines changed

src/WebJobs.Script/Workers/Profiles/WorkerDescriptionProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private string UseProfileOrDefault(string profileParameter, string defaultParame
9090

9191
private IList<string> UseProfileOrDefault(IList<string> profileParameter, IList<string> defaultParameter)
9292
{
93-
return profileParameter.Count > 0 ? profileParameter : defaultParameter;
93+
return profileParameter != null && profileParameter.Count > 0 ? profileParameter : defaultParameter;
9494
}
9595
}
9696
}

src/WebJobs.Script/Workers/Profiles/WorkerProfileConditionDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public sealed class WorkerProfileConditionDescriptor
1717

1818
private IDictionary<string, string> _properties;
1919

20-
[JsonProperty(Required = Required.Always)]
20+
[JsonProperty(Required = Required.Always, PropertyName = WorkerConstants.WorkerDescriptionProfileConditionType)]
2121
public string Type { get; set; }
2222

2323
public IDictionary<string, string> Properties

src/WebJobs.Script/Workers/Profiles/WorkerProfileDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.Azure.WebJobs.Script.Workers.Profiles
88
{
99
public sealed class WorkerProfileDescriptor
1010
{
11-
public string Name { get; set; }
11+
public string ProfileName { get; set; }
1212

1313
public RpcWorkerDescription Description { get; set; }
1414

src/WebJobs.Script/Workers/Rpc/Configuration/RpcWorkerConfigFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ private List<WorkerDescriptionProfile> ReadWorkerDescriptionProfiles(JToken prof
201201
if (!_profileManager.TryCreateWorkerProfileCondition(descriptor, out IWorkerProfileCondition condition))
202202
{
203203
// Failed to resolve condition. This profile will be disabled using a mock false condition
204-
_logger?.LogInformation($"Profile {profile.Name} is disabled. Cannot resolve the profile condition {descriptor.Type}");
204+
_logger?.LogInformation($"Profile {profile.ProfileName} is disabled. Cannot resolve the profile condition {descriptor.Type}");
205205
condition = new FalseCondition();
206206
}
207207

208208
profileConditions.Add(condition);
209209
}
210210

211-
descriptionProfiles.Add(new (profile.Name, profileConditions, profile.Description));
211+
descriptionProfiles.Add(new (profile.ProfileName, profileConditions, profile.Description));
212212
}
213213
}
214214
catch (Exception)

test/WebJobs.Script.Tests/Workers/Profiles/HostPropertyConditionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void HostPropertyConditionTest_EvaluateTrue(string name, string testExpre
5555
[Theory]
5656
//[InlineData("sku", "Dynamic")] TODO: Add test case
5757
[InlineData("platForm", "Windows")]
58-
[InlineData("HostVersion", "3.*")]
58+
[InlineData("HostVersion", "-1")]
5959
public void HostPropertyConditionTest_EvaluateFalse(string name, string testExpression)
6060
{
6161
var testLogger = new TestLogger("test");

test/WebJobs.Script.Tests/Workers/Profiles/ProfilesTestUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.Azure.WebJobs.Script.Tests.Workers.Profiles
1212
{
1313
public class ProfilesTestUtilities
1414
{
15-
public static JObject GetTestWorkerProfileCondition(string type = "hostproperty", string name = "hostversion", string expression = "4.*")
15+
public static JObject GetTestWorkerProfileCondition(string type = WorkerConstants.WorkerDescriptionProfileHostPropertyCondition, string name = "hostVersion", string expression = "4.*")
1616
{
1717
var condition = new JObject();
1818
condition[WorkerConstants.WorkerDescriptionProfileConditionType] = type;

test/WebJobs.Script.Tests/Workers/Rpc/RpcWorkerConfigTestUtilities.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class RpcWorkerConfigTestUtilities
1818
public const string HttpWorkerExe = "httpServer.exe";
1919
public const string TestDefaultExecutablePath = "testWorkerPath";
2020

21-
public static JObject GetTestWorkerConfig(string language, string[] arguments, bool invalid, string profileName, bool emptyWorkerPath = false)
21+
public static JObject GetTestWorkerConfig(string language, string[] arguments, bool invalid, string profileName, bool invalidProfile, bool emptyWorkerPath = false)
2222
{
2323
WorkerDescription description = GetTestDefaultWorkerDescription(language, arguments);
2424

@@ -32,10 +32,16 @@ public static JObject GetTestWorkerConfig(string language, string[] arguments, b
3232
DefaultExecutablePath = "myFooPath",
3333
};
3434

35-
JArray profiles = new JArray();
36-
JObject profile = new JObject();
35+
var profiles = new JArray();
36+
var profile = new JObject();
37+
var conditions = new JArray();
3738
profile[WorkerConstants.WorkerDescriptionProfileName] = "profileName";
38-
profile[WorkerConstants.WorkerDescriptionProfileConditions] = ProfilesTestUtilities.GetTestWorkerProfileCondition();
39+
if (invalidProfile)
40+
{
41+
conditions.Add(ProfilesTestUtilities.GetTestWorkerProfileCondition(WorkerConstants.WorkerDescriptionProfileHostPropertyCondition, "hostVersion", "-1"));
42+
}
43+
conditions.Add(ProfilesTestUtilities.GetTestWorkerProfileCondition());
44+
profile[WorkerConstants.WorkerDescriptionProfileConditions] = conditions;
3945
profile[WorkerConstants.WorkerDescription] = JObject.FromObject(appSvcDescription);
4046
profiles.Add(profile);
4147
config[WorkerConstants.WorkerDescriptionProfiles] = profiles;

test/WebJobs.Script.Tests/Workers/Rpc/RpcWorkerConfigTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void ReadWorkerProviderFromConfig_ArgumentsFromSettings()
115115
[Fact]
116116
public void ReadWorkerProviderFromConfig_EmptyWorkerPath()
117117
{
118-
var configs = new List<TestRpcWorkerConfig>() { MakeTestConfig(testLanguage, new string[0], false, string.Empty, true) };
118+
var configs = new List<TestRpcWorkerConfig>() { MakeTestConfig(testLanguage, new string[0], false, string.Empty, false, true) };
119119
TestMetricsLogger testMetricsLogger = new TestMetricsLogger();
120120

121121
var workerConfigs = TestReadWorkerProviderFromConfig(configs, new TestLogger(testLanguage), testMetricsLogger);
@@ -205,7 +205,7 @@ public void ReadWorkerProviderFromConfig_InvalidWorker()
205205
public void ReadWorkerProviderFromConfig_AddProfile_ReturnsDefaultDescription()
206206
{
207207
var expectedArguments = new string[] { "-v", "verbose" };
208-
var configs = new List<TestRpcWorkerConfig>() { MakeTestConfig(testLanguage, expectedArguments, false, "TestProfile") };
208+
var configs = new List<TestRpcWorkerConfig>() { MakeTestConfig(testLanguage, expectedArguments, false, "TestProfile", true) };
209209
var testLogger = new TestLogger(testLanguage);
210210
TestMetricsLogger testMetricsLogger = new TestMetricsLogger();
211211

@@ -672,9 +672,9 @@ private static IConfigurationRoot TestConfigBuilder(string workerPathSection, Di
672672
return config;
673673
}
674674

675-
private static TestRpcWorkerConfig MakeTestConfig(string language, string[] arguments, bool invalid = false, string addAppSvcProfile = "", bool emptyWorkerPath = false)
675+
private static TestRpcWorkerConfig MakeTestConfig(string language, string[] arguments, bool invalid = false, string addAppSvcProfile = "", bool invalidProfile = false, bool emptyWorkerPath = false)
676676
{
677-
string json = RpcWorkerConfigTestUtilities.GetTestWorkerConfig(language, arguments, invalid, addAppSvcProfile, emptyWorkerPath).ToString();
677+
string json = RpcWorkerConfigTestUtilities.GetTestWorkerConfig(language, arguments, invalid, addAppSvcProfile, invalidProfile, emptyWorkerPath).ToString();
678678
return new TestRpcWorkerConfig()
679679
{
680680
Json = json,

0 commit comments

Comments
 (0)