Skip to content

Commit d66fd05

Browse files
author
Christopher Anderson
committed
Added "worker" to config resolution
added test coverage for Worker Config Factory
1 parent c9ea20e commit d66fd05

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

src/WebJobs.Script/Rpc/Configuration/WorkerConfigFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public IEnumerable<WorkerConfig> GetConfigs(IEnumerable<IWorkerProvider> provide
2626
foreach (var provider in providers)
2727
{
2828
var description = provider.GetDescription();
29-
var languageSection = _config.GetSection(description.Language);
29+
var languageSection = _config.GetSection($"workers:{description.Language}");
3030

3131
// get explicit worker path from config, or build relative path from default
3232
var workerPath = languageSection.GetSection("path").Value;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.IO;
6+
using Microsoft.Azure.WebJobs.Script.Abstractions;
7+
using Microsoft.Azure.WebJobs.Script.Config;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
using Microsoft.Extensions.Options;
11+
12+
namespace Microsoft.Azure.WebJobs.Script.Tests
13+
{
14+
public class TestWorkerProvider : IWorkerProvider
15+
{
16+
public string Language { get; set; }
17+
18+
public string Extension { get; set; }
19+
20+
public string DefaultWorkerPath { get; set; }
21+
22+
public WorkerDescription GetDescription() => new WorkerDescription
23+
{
24+
Language = this.Language,
25+
Extension = this.Extension,
26+
DefaultWorkerPath = this.DefaultWorkerPath,
27+
};
28+
29+
public bool TryConfigureArguments(ArgumentsDescription args, IConfiguration config, ILogger logger)
30+
{
31+
// make no modifications
32+
return true;
33+
}
34+
}
35+
}

test/WebJobs.Script.Tests.Shared/WebJobs.Script.Tests.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
<Compile Include="$(MSBuildThisFileDirectory)TestSecretManager.cs" />
2424
<Compile Include="$(MSBuildThisFileDirectory)TestSecretManagerFactory.cs" />
2525
<Compile Include="$(MSBuildThisFileDirectory)TestTraceWriter.cs" />
26+
<Compile Include="$(MSBuildThisFileDirectory)TestWorkerProvider.cs" />
2627
</ItemGroup>
2728
</Project>

test/WebJobs.Script.Tests/Description/Proxy/ProxyFunctionDescriptorProviderTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public ProxyFunctionDescriptorProviderTests()
4242

4343
_proxyClient = GetMockProxyClient();
4444
_settingsManager = ScriptSettingsManager.Instance;
45+
_settingsManager.Reset();
4546
_host = ScriptHost.Create(environment.Object, eventManager.Object, _config, _settingsManager, proxyClient: _proxyClient);
4647
_metadataCollection = _host.ReadProxyMetadata(_config, _settingsManager);
4748
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using Microsoft.Azure.WebJobs.Script.Abstractions;
8+
using Microsoft.Azure.WebJobs.Script.Rpc;
9+
using Microsoft.Extensions.Configuration;
10+
using Microsoft.WebJobs.Script.Tests;
11+
using Xunit;
12+
13+
namespace Microsoft.Azure.WebJobs.Script.Tests.Rpc
14+
{
15+
public class WorkerConfigFactoryTests
16+
{
17+
[Fact]
18+
public void SetsDebugPort()
19+
{
20+
var lang = "test";
21+
var extension = ".test";
22+
var defaultWorkerPath = "./test";
23+
24+
var workerPath = "/path/to/custom/worker";
25+
26+
var config = new ConfigurationBuilder()
27+
.AddInMemoryCollection(new List<KeyValuePair<string, string>>()
28+
{
29+
new KeyValuePair<string, string>($"workers:{lang}:debug", "1000"),
30+
new KeyValuePair<string, string>($"workers:{lang}:path", workerPath),
31+
})
32+
.Build();
33+
34+
var logger = new TestLogger("test");
35+
var workerConfigFactory = new WorkerConfigFactory(config, logger);
36+
37+
var workerConfigs = workerConfigFactory.GetConfigs(new List<IWorkerProvider>()
38+
{
39+
new TestWorkerProvider()
40+
{
41+
Language = lang,
42+
Extension = extension,
43+
DefaultWorkerPath = defaultWorkerPath
44+
}
45+
});
46+
47+
Assert.Equal(workerConfigs.Single().Arguments.WorkerPath, workerPath);
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)