-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Prepared working solution of Postgres that can be used with integration tests (#1) * PortWatcher implementation * PostgresBinaryLocator implementation * Move code one level up in repo * PostgresRunner implementation * Introduced Postgresinitializator process starter; throw exception when process return error code; bum dotnet standard to v2.0; setup basic test * distinguish pg executables based on os platform; fix long polling of free tcp port * Added missed binaries of postgres (3 os platforms supported by net core) * Updated linux based postgres binaries * Provided sample test suit how to execute pgrunner inside of xunit class fixture * Removed OSX binaries; OSX as OS Platform won't be supported till issue of it binaries size will be resolved * Fix Postgres Runner disposable procedure -there are no more thrown exception nor custom finalization; Postgres server start process is not disposable anymore cause it is one time call to pg_ctrl; Postgres server stop process is not throwing exceptions anymore - it should report only own output buffer; * Added possibility so specify database which will be used to build connection string * PostgresRunner doesn't use try/catch block in constructor anymore; instead Start() function is responsible for constructing and preparing running PostgresRunner instance; in case when running Postgres failed then PostgresRunner instance should be disposed. * Provided xunit.runner.visualstudio to Postgres2Go.Samples so tests can be run directly from IDE (vs or rider) * Corrected licensing (#18) Corrected licensing * #15 use options object in PostgresRunner API * #15 use options object in PostgresRunner API
- Loading branch information
1 parent
2ff0d53
commit b313eee
Showing
2,717 changed files
with
138,538 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
x64/ | ||
x86/ | ||
bld/ | ||
[Bb]in/ | ||
src/[Bb]in/ | ||
[Oo]bj/ | ||
[Ll]og/ | ||
|
||
|
Empty file.
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,6 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2013 | ||
VisualStudioVersion = 12.0.0.0 | ||
Global | ||
EndGlobal |
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 |
---|---|---|
@@ -1,2 +1,20 @@ | ||
# Postgres2Go | ||
Postgres2Go - PostgreSQL for integration tests | ||
Postgres2Go | ||
=========== | ||
> Postgres2Go - PostgreSQL for integration tests | ||
## Description | ||
# Installation | ||
# Usage | ||
|
||
|
||
## Credits | ||
Copyright (c) 2018 [Skyrise](http://skyrise.tech) | ||
|
||
Special thanks to all [Contributors](CREDITS.md) | ||
|
||
|
||
# License | ||
|
||
This software is distributed under [MIT License](LICENSE.md). | ||
|
||
It contains third-party files located in the tools folder that are distributed under [PostgreSQL License](tools/LICENSE.md) |
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" /> | ||
<PackageReference Include="more.xunit.runner.visualstudio" Version="2.3.1" /> | ||
<PackageReference Include="Npgsql" Version="3.2.6" /> | ||
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" /> | ||
<PackageReference Include="xunit" Version="2.3.1" /> | ||
<PackageReference Include="xunit.analyzers" Version="0.8.0" /> | ||
<PackageReference Include="xunit.runner.console" Version="2.3.1" /> | ||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Postgres2Go\Postgres2Go.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Npgsql; | ||
using Xunit; | ||
|
||
namespace Postgres2Go.Samples | ||
{ | ||
public class PgFixture : IDisposable | ||
{ | ||
private readonly PostgresRunner _pgRunner; | ||
|
||
public PgFixture() | ||
{ | ||
_pgRunner = PostgresRunner | ||
.Start(new PostgresRunnerOptions{ BinariesSearchPattern = GetPgBinariesRelativePath()}); | ||
} | ||
|
||
public void Dispose() => _pgRunner?.Dispose(); | ||
|
||
public string ConnectionString => _pgRunner.GetConnectionString(); | ||
|
||
private string GetPgBinariesRelativePath() | ||
{ | ||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
return "\\tools\\pgsql-10.1-windows64-binaries\\bin"; | ||
else if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
return "/tools/pgsql-10.1-linux-binaries/bin"; | ||
else | ||
throw new NotSupportedException("OSX is not yet supported"); | ||
} | ||
} | ||
|
||
public class when_using_as_class_fixture : IClassFixture<PgFixture> | ||
{ | ||
private readonly PgFixture _fixture; | ||
|
||
public when_using_as_class_fixture(PgFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task should_create_new_database_and_allow_exec_query_1() | ||
{ | ||
// PREPARE | ||
var dbName = "test_db_1"; | ||
|
||
var cmdBuilder = new StringBuilder(); | ||
cmdBuilder.AppendLine($"CREATE DATABASE {dbName}"); | ||
cmdBuilder.AppendLine("CONNECTION LIMIT = -1"); | ||
|
||
// RUN | ||
using (var conn = new Npgsql.NpgsqlConnection(_fixture.ConnectionString)) | ||
{ | ||
await conn.OpenAsync(); | ||
var cmd = new NpgsqlCommand(cmdBuilder.ToString(), conn); | ||
cmd.ExecuteNonQuery(); | ||
|
||
// ASSERT | ||
var dbExists = await new NpgsqlCommand($"SELECT datname FROM pg_catalog.pg_database WHERE datname = '{dbName}'",conn) | ||
.ExecuteScalarAsync(); | ||
|
||
Assert.NotNull(dbExists); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task should_create_new_database_and_allow_exec_query_2() | ||
{ | ||
// PREPARE | ||
var dbName = "test_db_2"; | ||
|
||
var cmdBuilder = new StringBuilder(); | ||
cmdBuilder.AppendLine($"CREATE DATABASE {dbName}"); | ||
cmdBuilder.AppendLine("CONNECTION LIMIT = -1"); | ||
|
||
// RUN | ||
using (var conn = new Npgsql.NpgsqlConnection(_fixture.ConnectionString)) | ||
{ | ||
await conn.OpenAsync(); | ||
var cmd = new NpgsqlCommand(cmdBuilder.ToString(), conn); | ||
cmd.ExecuteNonQuery(); | ||
|
||
// ASSERT | ||
var dbExists = await new NpgsqlCommand($"SELECT datname FROM pg_catalog.pg_database WHERE datname = '{dbName}'",conn) | ||
.ExecuteScalarAsync(); | ||
|
||
Assert.NotNull(dbExists); | ||
} | ||
} | ||
} | ||
} |
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" /> | ||
<PackageReference Include="xunit" Version="2.3.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | ||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Postgres2Go\Postgres2Go.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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,41 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27130.2020 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Postgres2Go", "Postgres2Go\Postgres2Go.csproj", "{DC273622-0954-432E-A722-8E0D7C78E21B}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Postgres2Go.Tests", "Postgres2Go.Tests\Postgres2Go.Tests.csproj", "{D9527249-990B-4557-8DC1-FA9434F46A82}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EB802F83-E581-4C4B-9B16-7D00D66C9329}" | ||
ProjectSection(SolutionItems) = preProject | ||
GCop.json = GCop.json | ||
EndProjectSection | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Postgres2Go.Samples", "Postgres2Go.Samples\Postgres2Go.Samples.csproj", "{DB99F089-0B3C-4963-A194-6BFAAA619D2E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DC273622-0954-432E-A722-8E0D7C78E21B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DC273622-0954-432E-A722-8E0D7C78E21B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DC273622-0954-432E-A722-8E0D7C78E21B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DC273622-0954-432E-A722-8E0D7C78E21B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{D9527249-990B-4557-8DC1-FA9434F46A82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D9527249-990B-4557-8DC1-FA9434F46A82}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D9527249-990B-4557-8DC1-FA9434F46A82}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D9527249-990B-4557-8DC1-FA9434F46A82}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{DB99F089-0B3C-4963-A194-6BFAAA619D2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DB99F089-0B3C-4963-A194-6BFAAA619D2E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DB99F089-0B3C-4963-A194-6BFAAA619D2E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DB99F089-0B3C-4963-A194-6BFAAA619D2E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {4857BFD8-1DB9-4BFA-BDAA-1D8B9B9386E7} | ||
EndGlobalSection | ||
EndGlobal |
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,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace Postgres2Go.Common | ||
{ | ||
internal enum RecognizedOSPlatformEnum | ||
{ | ||
Unknown = 0, | ||
Windows = 1, | ||
Linux = 2, | ||
OSX = 3 | ||
} | ||
|
||
internal static class RecognizedOSPlatform | ||
{ | ||
internal static RecognizedOSPlatformEnum Determine() | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
return RecognizedOSPlatformEnum.Windows; | ||
} | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
return RecognizedOSPlatformEnum.Linux; | ||
} | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
{ | ||
return RecognizedOSPlatformEnum.OSX; | ||
} | ||
|
||
return RecognizedOSPlatformEnum.Unknown; | ||
} | ||
} | ||
} |
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,11 @@ | ||
using System; | ||
|
||
namespace Postgres2Go.Common | ||
{ | ||
public class UnsupportedPlatformException : Exception | ||
{ | ||
public UnsupportedPlatformException() { } | ||
public UnsupportedPlatformException(string message) : base(message) { } | ||
public UnsupportedPlatformException(string message, Exception inner) : base(message, inner) { } | ||
} | ||
} |
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,43 @@ | ||
using System.IO; | ||
|
||
namespace Postgres2Go.Helper.FileSystem | ||
{ | ||
internal static class FileSystem | ||
{ | ||
internal static void CreateFolder(string path) | ||
{ | ||
if (!Directory.Exists(path)) | ||
{ | ||
Directory.CreateDirectory(path); | ||
} | ||
} | ||
|
||
internal static void DeleteFolder(string path) | ||
{ | ||
if (Directory.Exists(path)) | ||
{ | ||
Directory.Delete(path, true); | ||
} | ||
} | ||
|
||
internal static void DeleteFile(string fullFileName) | ||
{ | ||
if (File.Exists(fullFileName)) | ||
{ | ||
File.Delete(fullFileName); | ||
} | ||
} | ||
|
||
internal static void GrantExecutablePermission(string path) | ||
{ | ||
var p = System.Diagnostics.Process.Start("chmod", $"+x {path}"); | ||
p.WaitForExit(); | ||
|
||
if (p.ExitCode != 0) | ||
{ | ||
throw new System.IO.IOException($"Could not set executable bit for {path}"); | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.