public void Runner_WhenTimedOut_ThrowsExcption() { ScriptRunnerOptions opts = new ScriptRunnerOptions(); opts.ScriptDirectory = Path.Combine(Utils.GetProjectRootDirectory(), Constants.ScriptsRelativePath); opts.ScriptTimeout = 1; // one millisecond opts.ScriptExitTimeout = 10; var accessor = new OptionsAccessor <ScriptRunnerOptions> { Value = opts }; ILogger <ScriptRunner> logger = platform.ServiceProvider.GetService <ILoggerFactory>().CreateLogger <ScriptRunner>(); IScriptPlatform scriptPlatform; if (new StdOSDetector().DetectOS() == Os.Windows) { scriptPlatform = new CmdScriptPlatform(platform.ServiceProvider.GetService <ILoggerFactory>().CreateLogger <CmdScriptPlatform>()); } else { scriptPlatform = new BashScriptPlatform(platform.ServiceProvider.GetService <ILoggerFactory>().CreateLogger <BashScriptPlatform>()); } ScriptRunner runner = new ScriptRunner(accessor, logger, scriptPlatform); Assert.Throws <Exception>(() => runner.Run("TestScript", runner.DefaultEnv, false)); }
public void DetectChangesScript_WhenCleanDirectory_ReturnsNothing() { var runner = platform.ServiceProvider.GetService <IScriptRunner>(); (var exitCode, _) = runner.Run("DetectChanges", runner.DefaultEnv, false // ); , Path.Combine(Utils.GetProjectRootDirectory(), Constants.VanillaTestData)); Assert.Equal(0, exitCode); }
private void InjectDependenciesAll() { services.Configure <ScriptRunnerOptions>( opts => { opts.ScriptDirectory = Path.Combine(SupportUtils.GetProjectRootDirectory(), Constants.ScriptsRelativePath); opts.ScriptTimeout = Constants.DefaultScriptTimeout; if (Int32.TryParse(Environment.GetEnvironmentVariable(Constants.DasBlogTestScriptTimeout), out var envScriptTimeout)) { opts.ScriptTimeout = envScriptTimeout; } opts.ScriptExitTimeout = Constants.DefaultScriptExitDelay; if (Int32.TryParse(Environment.GetEnvironmentVariable(Constants.DasBlogTestScriptExitDelay), out var envScriptExitTimeout)) { opts.ScriptExitTimeout = envScriptExitTimeout; } }); var repoPathEnvVar = Environment.GetEnvironmentVariable(Constants.DasBlogGitRepo); services.Configure <GitVersionedFileServiceOptions>( opts => { opts.GitRepoDirectory = SupportUtils.GetProjectRootDirectory(); opts.TestDataDirectroy = Constants.TestDataDirectory; }); if (new DasBlog.Core.Common.StdOSDetector().DetectOS() == Os.Windows) { services.AddSingleton <IScriptPlatform, CmdScriptPlatform>(); } else { services.AddSingleton <IScriptPlatform, BashScriptPlatform>(); } services.AddSingleton <IScriptRunner, ScriptRunner>(); services.AddSingleton <IVersionedFileService, GitVersionedFileService>(); services.AddSingleton <IDasBlogSandboxFactory, DasBlogSandboxFactory>(); services.AddSingleton <ITestDataProcesorFactory, TestDataProcesorFactory>(); ConfigurationBuilder configBuilder = new ConfigurationBuilder(); configBuilder.AddJsonFile( Path.Combine(SupportUtils.GetProjectRootDirectory(), Constants.FunctionalTestsRelativeToProject, "appsettings.json") , optional: false, reloadOnChange: false); // the derived platform app settings will have precedence over the more general ones // by dint of being added to the configuration later configBuilder.AddJsonFile( Path.Combine(SupportUtils.GetProjectRootDirectory(), AppSettingsPathRelativeToProject, "appsettings.json") , optional: false, reloadOnChange: false); IConfigurationRoot config = configBuilder.Build(); services.Configure <ILoggerFactory>(config); services.AddLogging( opts => { opts.AddConfiguration(config.GetSection("Logging")); opts.SetMinimumLevel(LogLevel.Information); }); InjectDependencies(services); // add in the derived class's dependencies ServiceProvider = services.BuildServiceProvider(); }