This repository has been archived by the owner on May 9, 2022. It is now read-only.
forked from nmklotas/GitLabApiClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add collection fixture for gitlab docker instance * Fix docker config * Add collection attributes * add travis.yml * Update .travis.yml * Update GitLabContainerFixture.cs
- Loading branch information
Showing
10 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: csharp | ||
mono: none | ||
dotnet: 2.0.0 | ||
dist: trusty | ||
sudo: required | ||
services: | ||
- docker | ||
script: | ||
- dotnet build | ||
- (cd ./test/GitLabApiClient.Test && dotnet test) | ||
cache: | ||
directories: | ||
- $HOME/.nuget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
test/GitLabApiClient.Test/Utilities/GitLabContainerFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace GitLabApiClient.Test.Utilities | ||
{ | ||
public class GitLabContainerFixture : IAsyncLifetime | ||
{ | ||
private const string GitLabContainerPath = "../../../../docker"; | ||
|
||
private const string GitLabApiPath = "http://localhost:9190/"; | ||
|
||
private static readonly TimeSpan TestTimeout = TimeSpan.FromMinutes(10); | ||
|
||
private HttpClient _gitLabPingClient; | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
_gitLabPingClient = new HttpClient | ||
{ | ||
Timeout = TimeSpan.FromSeconds(1) | ||
}; | ||
|
||
StartContainer(); | ||
if (!await WaitForService()) | ||
throw new Exception($"Failed to start container, timeout hit."); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
StopContainer(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
private void StartContainer() | ||
{ | ||
StartProcessAndWaitForExit(new ProcessStartInfo | ||
{ | ||
FileName = "docker-compose", | ||
Arguments = | ||
$"-f {GitLabContainerPath}/docker-compose.yml up -d" | ||
}); | ||
} | ||
|
||
private void StopContainer() | ||
{ | ||
var processStartInfo = new ProcessStartInfo | ||
{ | ||
FileName = "docker-compose", | ||
Arguments = | ||
$"-f {GitLabContainerPath}/docker-compose.yml down" | ||
}; | ||
|
||
StartProcessAndWaitForExit(processStartInfo); | ||
} | ||
|
||
private void StartProcessAndWaitForExit(ProcessStartInfo processStartInfo) | ||
{ | ||
processStartInfo.Environment["COMPUTERNAME"] = Environment.MachineName; | ||
|
||
var process = Process.Start(processStartInfo); | ||
process.WaitForExit(); | ||
Assert.Equal(0, process.ExitCode); | ||
} | ||
|
||
private async Task<bool> WaitForService() | ||
{ | ||
var startTime = DateTime.Now; | ||
|
||
while (DateTime.Now - startTime < TestTimeout) | ||
{ | ||
try | ||
{ | ||
var response = await _gitLabPingClient.GetAsync(GitLabApiPath); | ||
if (response.IsSuccessStatusCode) | ||
{ | ||
Debug.WriteLine("GitLab started to respond!"); | ||
return true; | ||
} | ||
} | ||
catch | ||
{ | ||
} | ||
|
||
await Task.Delay(5000); | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/GitLabApiClient.Test/Utilities/GitLabContainterFixtureCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace GitLabApiClient.Test.Utilities | ||
{ | ||
[CollectionDefinition("GitLabContainerFixture")] | ||
public class GitLabContainterFixtureCollection : ICollectionFixture<GitLabContainerFixture> | ||
{ | ||
} | ||
} |