public void InValid_HttpWorkerConfig_Throws_HostConfigurationException() { string hostJsonContent = @"{ 'version': '2.0', 'httpWorker': { 'invalid': { 'defaultExecutablePath': 'testExe' } } }"; File.WriteAllText(_hostJsonFile, hostJsonContent); var configuration = BuildHostJsonConfiguration(); HttpWorkerOptionsSetup setup = new HttpWorkerOptionsSetup(new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions), configuration, _testLoggerFactory); HttpWorkerOptions options = new HttpWorkerOptions(); var ex = Assert.Throws <HostConfigurationException>(() => setup.Configure(options)); Assert.Contains("Missing WorkerDescription for HttpWorker", ex.Message); }
public void HttpWorkerConfig_OverrideConfigViaEnvVars_Test() { string hostJsonContent = @"{ 'version': '2.0', 'httpWorker': { 'description': { 'langauge': 'testExe', 'defaultExecutablePath': 'dotnet', 'defaultWorkerPath':'ManualTrigger/run.csx', 'arguments': ['--xTest1 --xTest2'], 'workerArguments': ['--xTest3 --xTest4'] } } }"; try { File.WriteAllText(_hostJsonFile, hostJsonContent); Environment.SetEnvironmentVariable("AzureFunctionsJobHost:httpWorker:description:defaultWorkerPath", "OneSecondTimer/run.csx"); Environment.SetEnvironmentVariable("AzureFunctionsJobHost:httpWorker:description:arguments", "[\"--xTest5\", \"--xTest6\", \"--xTest7\"]"); var configuration = BuildHostJsonConfiguration(); HttpWorkerOptionsSetup setup = new HttpWorkerOptionsSetup(new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions), configuration, _testLoggerFactory, _metricsLogger); HttpWorkerOptions options = new HttpWorkerOptions(); setup.Configure(options); Assert.Equal("dotnet", options.Description.DefaultExecutablePath); // Verify options are overridden Assert.Contains("OneSecondTimer/run.csx", options.Description.DefaultWorkerPath); Assert.Equal(3, options.Description.Arguments.Count); Assert.Contains("--xTest5", options.Description.Arguments); Assert.Contains("--xTest6", options.Description.Arguments); Assert.Contains("--xTest7", options.Description.Arguments); // Verify options not overridden Assert.Equal(1, options.Description.WorkerArguments.Count); Assert.Equal("--xTest3 --xTest4", options.Description.WorkerArguments.ElementAt(0)); } finally { Environment.SetEnvironmentVariable("AzureFunctionsJobHost:httpWorker:description:defaultWorkerPath", string.Empty); Environment.SetEnvironmentVariable("AzureFunctionsJobHost:httpWorker:description:arguments", string.Empty); } }
public void MissingOrValid_HttpWorkerConfig_DoesNotThrowException(string hostJsonContent) { File.WriteAllText(_hostJsonFile, hostJsonContent); var configuration = BuildHostJsonConfiguration(); HttpWorkerOptionsSetup setup = new HttpWorkerOptionsSetup(new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions), configuration, _testLoggerFactory, _metricsLogger); HttpWorkerOptions options = new HttpWorkerOptions(); options.Description = new HttpWorkerDescription(); options.Description.FileExists = path => { return(true); }; setup.Configure(options); if (options.Description != null && !string.IsNullOrEmpty(options.Description.DefaultExecutablePath)) { string expectedDefaultExecutablePath = Path.Combine(_scriptJobHostOptions.RootScriptPath, "testExe"); Assert.Equal(expectedDefaultExecutablePath, options.Description.DefaultExecutablePath); } }
public void InValid_HttpWorkerConfig_Throws_Exception(string hostJsonContent) { File.WriteAllText(_hostJsonFile, hostJsonContent); var configuration = BuildHostJsonConfiguration(); HttpWorkerOptionsSetup setup = new HttpWorkerOptionsSetup(new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions), configuration, _testLoggerFactory, _metricsLogger); HttpWorkerOptions options = new HttpWorkerOptions(); var ex = Record.Exception(() => setup.Configure(options)); Assert.NotNull(ex); if (options.Description == null) { Assert.IsType <HostConfigurationException>(ex); Assert.Equal($"Missing worker Description.", ex.Message); } else { Assert.IsType <ValidationException>(ex); Assert.Equal($"WorkerDescription DefaultExecutablePath cannot be empty", ex.Message); } }
public void HttpWorker_Config_ExpectedValues(string hostJsonContent, bool appendCurrentDirectoryToExe, bool appendCurrentDirToWorkerPath, bool workerPathSet) { File.WriteAllText(_hostJsonFile, hostJsonContent); var configuration = BuildHostJsonConfiguration(); HttpWorkerOptionsSetup setup = new HttpWorkerOptionsSetup(new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions), configuration, _testLoggerFactory, _metricsLogger); HttpWorkerOptions options = new HttpWorkerOptions(); setup.Configure(options); //Verify worker exe path is expected if (appendCurrentDirectoryToExe) { Assert.Equal(Path.Combine(_scriptJobHostOptions.RootScriptPath, "node"), options.Description.DefaultExecutablePath); } else if (Path.IsPathRooted(options.Description.DefaultExecutablePath)) { Assert.Equal(@"c:/myruntime/node", options.Description.DefaultExecutablePath); } else { Assert.Equal("node", options.Description.DefaultExecutablePath); } //Verify worker path is expected if (appendCurrentDirToWorkerPath) { Assert.Equal("httpWorker.js", options.Description.DefaultWorkerPath); } else if (!workerPathSet) { Assert.Null(options.Description.DefaultWorkerPath); } else { Assert.Equal(@"c:/myworkerPath/httpWorker.js", options.Description.DefaultWorkerPath); } Assert.Equal(1, options.Description.Arguments.Count); Assert.Equal("--xTest1 --xTest2", options.Description.Arguments[0]); }