-
Notifications
You must be signed in to change notification settings - Fork 6
enable to pass environment variables from outside #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,9 +32,9 @@ public DockerFixture(IMessageSink output) | |
| /// If you call this multiple times on the same DockerFixture then it will be ignored. | ||
| /// </summary> | ||
| /// <param name="setupOptions">Options that control how docker-compose is executed.</param> | ||
| public void InitOnce(Func<IDockerFixtureOptions> setupOptions) | ||
| public async Task InitOnceAsync(Func<IDockerFixtureOptions> setupOptions) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whilst I have no problem with this being async, just remember that as a fixture people will be calling this from a constructor (which are inherently synchronous). So they will have to do a .GetAwaiter().GetResult(). However if you are firing off multiple async Tasks then this would still make sense. |
||
| { | ||
| InitOnce(setupOptions, null); | ||
| await InitOnceAsync(setupOptions, null); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -43,11 +43,11 @@ public void InitOnce(Func<IDockerFixtureOptions> setupOptions) | |
| /// </summary> | ||
| /// <param name="setupOptions">Options that control how docker-compose is executed.</param> | ||
| /// <param name="dockerCompose"></param> | ||
| public void InitOnce(Func<IDockerFixtureOptions> setupOptions, IDockerCompose dockerCompose) | ||
| public async Task InitOnceAsync(Func<IDockerFixtureOptions> setupOptions, IDockerCompose dockerCompose) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| { | ||
| if (!this.initialised) | ||
| { | ||
| this.Init(setupOptions, dockerCompose); | ||
| await this.InitAsync(setupOptions, dockerCompose); | ||
| this.initialised = true; | ||
| } | ||
| } | ||
|
|
@@ -57,26 +57,26 @@ public void InitOnce(Func<IDockerFixtureOptions> setupOptions, IDockerCompose do | |
| /// Initialize docker compose services from file(s). | ||
| /// </summary> | ||
| /// <param name="setupOptions">Options that control how docker-compose is executed</param> | ||
| public void Init(Func<IDockerFixtureOptions> setupOptions) | ||
| public async Task InitAsync(Func<IDockerFixtureOptions> setupOptions) | ||
| { | ||
| Init(setupOptions, null); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| await InitAsync(setupOptions, null); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initialize docker compose services from file(s). | ||
| /// </summary> | ||
| /// <param name="setupOptions">Options that control how docker-compose is executed</param> | ||
| /// <param name="compose"></param> | ||
| public void Init(Func<IDockerFixtureOptions> setupOptions, IDockerCompose compose) | ||
| public async Task InitAsync(Func<IDockerFixtureOptions> setupOptions, IDockerCompose compose) | ||
| { | ||
| var options = setupOptions(); | ||
| options.Validate(); | ||
| string logFile = options.DebugLog | ||
| ? Path.Combine(Path.GetTempPath(), $"docker-compose-{DateTime.Now.Ticks}.log") | ||
| : null; | ||
|
|
||
| this.Init(options.DockerComposeFiles, options.DockerComposeUpArgs, options.DockerComposeDownArgs, | ||
| options.StartupTimeoutSecs, options.CustomUpTest, compose, this.GetLoggers(logFile).ToArray()); | ||
| await this.InitAsync(options.DockerComposeFiles, options.DockerComposeUpArgs, options.DockerComposeDownArgs, | ||
| options.StartupTimeoutSecs, options.CustomUpTest, compose, this.GetLoggers(logFile).ToArray(), options.EnvironmentVariables); | ||
| } | ||
|
|
||
| private IEnumerable<ILogger> GetLoggers(string file) | ||
|
|
@@ -103,14 +103,15 @@ private IEnumerable<ILogger> GetLoggers(string file) | |
| /// <param name="customUpTest">Checks whether the docker-compose services have come up correctly based upon the output of docker-compose</param> | ||
| /// <param name="dockerCompose"></param> | ||
| /// <param name="logger"></param> | ||
| public void Init(string[] dockerComposeFiles, string dockerComposeUpArgs, string dockerComposeDownArgs, | ||
| /// <param name="environmentVariables"></param> | ||
| public async Task InitAsync(string[] dockerComposeFiles, string dockerComposeUpArgs, string dockerComposeDownArgs, | ||
| int startupTimeoutSecs, Func<string[], bool> customUpTest = null, | ||
| IDockerCompose dockerCompose = null, ILogger[] logger = null) | ||
| IDockerCompose dockerCompose = null, ILogger[] logger = null, IEnumerable<KeyValuePair<string, object>> environmentVariables = null) | ||
| { | ||
| this.loggers = logger ?? GetLoggers(null).ToArray(); | ||
|
|
||
| var dockerComposeFilePaths = dockerComposeFiles.Select(this.GetComposeFilePath); | ||
| this.dockerCompose = dockerCompose ?? new DockerCompose(this.loggers); | ||
| this.dockerCompose = dockerCompose ?? new DockerCompose(this.loggers, environmentVariables); | ||
| this.customUpTest = customUpTest; | ||
| this.startupTimeoutSecs = startupTimeoutSecs; | ||
|
|
||
|
|
@@ -119,7 +120,7 @@ public void Init(string[] dockerComposeFiles, string dockerComposeUpArgs, string | |
| dockerComposeFilePaths | ||
| .Select(f => $"-f \"{f}\"")) | ||
| .Trim(), dockerComposeUpArgs, dockerComposeDownArgs); | ||
| this.Start(); | ||
| await this.StartAsync(); | ||
| } | ||
|
|
||
| private string GetComposeFilePath(string file) | ||
|
|
@@ -195,7 +196,7 @@ public virtual void Dispose() | |
| this.Stop(); | ||
| } | ||
|
|
||
| private void Start() | ||
| private async Task StartAsync() | ||
| { | ||
| if (this.CheckIfRunning().hasContainers) | ||
| { | ||
|
|
@@ -214,7 +215,7 @@ private void Start() | |
| break; | ||
| } | ||
| this.loggers.Log($"---- checking docker services ({i + 1}/{this.startupTimeoutSecs}) ----"); | ||
| Thread.Sleep(this.dockerCompose.PauseMs); | ||
| await Task.Delay(1000); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve the use of PauseMs |
||
| if (this.customUpTest != null) | ||
| { | ||
| if (this.customUpTest(this.loggers.GetLoggedLines())) | ||
|
|
@@ -252,7 +253,5 @@ private void Stop() | |
| { | ||
| this.dockerCompose.Down(); | ||
| } | ||
|
|
||
|
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this an IEnumerable<KeyValuePair<,>> instead of a IDictionary<,>? If it is so that the order of the env vars can be preserved then does the order matter?