public void DefaultWorkerConfigs_Overrides_DefaultWorkerRuntimeVersion_AppSetting()
        {
            var testEnvVariables = new Dictionary <string, string>
            {
                { "languageWorkers:python:defaultRuntimeVersion", "3.8" }
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(testEnvVariables);
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");

            using (var variables = new TestScopedSettings(scriptSettingsManager, testEnvVariables))
            {
                var configFactory          = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment, new TestMetricsLogger());
                var workerConfigs          = configFactory.GetConfigs();
                var pythonWorkerConfig     = workerConfigs.Where(w => w.Description.Language.Equals("python", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                var powershellWorkerConfig = workerConfigs.Where(w => w.Description.Language.Equals("powershell", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                Assert.Equal(4, workerConfigs.Count);
                Assert.NotNull(pythonWorkerConfig);
                Assert.NotNull(powershellWorkerConfig);
                Assert.Equal("3.8", pythonWorkerConfig.Description.DefaultRuntimeVersion);
                Assert.Equal("6", powershellWorkerConfig.Description.DefaultRuntimeVersion);
            }
        }
        public void JavaPath_FromEnvVars()
        {
            var configBuilder         = ScriptSettingsManager.CreateDefaultConfigurationBuilder();
            var config                = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");
            var configFactory         = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment, new TestMetricsLogger());
            var workerConfigs         = configFactory.GetConfigs();
            var javaPath              = workerConfigs.Where(c => c.Description.Language.Equals("java", StringComparison.OrdinalIgnoreCase)).FirstOrDefault().Description.DefaultExecutablePath;

            Assert.DoesNotContain(@"%JAVA_HOME%", javaPath);
            Assert.Contains(@"/bin/java", javaPath);
        }
Exemplo n.º 3
0
        private IEnumerable <RpcWorkerConfig> TestReadWorkerProviderFromConfig(IEnumerable <TestRpcWorkerConfig> configs, ILogger testLogger, TestMetricsLogger testMetricsLogger, string language = null, Dictionary <string, string> keyValuePairs = null, bool appSvcEnv = false)
        {
            Mock <IEnvironment> mockEnvironment = new Mock <IEnvironment>();
            var workerPathSection = $"{RpcWorkerConstants.LanguageWorkersSectionName}:{WorkerConstants.WorkersDirectorySectionName}";

            try
            {
                foreach (var workerConfig in configs)
                {
                    RpcWorkerConfigTestUtilities.CreateWorkerFolder(rootPath, workerConfig);
                }

                IConfigurationRoot config = TestConfigBuilder(workerPathSection, keyValuePairs);

                var scriptHostOptions     = new ScriptJobHostOptions();
                var scriptSettingsManager = new ScriptSettingsManager(config);
                var configFactory         = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment, testMetricsLogger);
                if (appSvcEnv)
                {
                    var testEnvVariables = new Dictionary <string, string>
                    {
                        { EnvironmentSettingNames.AzureWebsiteInstanceId, "123" },
                    };
                    using (var variables = new TestScopedSettings(scriptSettingsManager, testEnvVariables))
                    {
                        configFactory.BuildWorkerProviderDictionary();
                        return(configFactory.GetConfigs());
                    }
                }
                configFactory.BuildWorkerProviderDictionary();
                return(configFactory.GetConfigs());
            }
            finally
            {
                RpcWorkerConfigTestUtilities.DeleteTestDir(rootPath);
                RpcWorkerConfigTestUtilities.DeleteTestDir(customRootPath);
            }
        }
        public void DefaultWorkerConfigs_Overrides_VersionAppSetting()
        {
            var testEnvironment = new TestEnvironment();

            testEnvironment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME_VERSION", "7.0");
            testEnvironment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", "powerShell");
            var configBuilder          = ScriptSettingsManager.CreateDefaultConfigurationBuilder();
            var config                 = configBuilder.Build();
            var scriptSettingsManager  = new ScriptSettingsManager(config);
            var testLogger             = new TestLogger("test");
            var configFactory          = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, testEnvironment, new TestMetricsLogger());
            var workerConfigs          = configFactory.GetConfigs();
            var powershellWorkerConfig = workerConfigs.Where(w => w.Description.Language.Equals("powershell", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            Assert.Equal(1, workerConfigs.Count);
            Assert.NotNull(powershellWorkerConfig);
            Assert.Equal("7", powershellWorkerConfig.Description.DefaultRuntimeVersion);
        }