Skip to content

Commit

Permalink
Merge pull request #46 from bt-skyrise/release/0.3.0
Browse files Browse the repository at this point in the history
Release/0.3.0


#36 fix: linux pg setup includes recreation of symbolic links
#35 Print whole output of Postgres process
#34 FolderSearch throws NotImplementedException
#33 target multiple dotnet versions
#25 - use combination of path's segments instead of concatenation
#3 - include copyright of Johannes Hoppe (author of Mongo2Go project)
  • Loading branch information
zabrowarnyrafal committed Feb 28, 2018
2 parents 8ab35e7 + 2c994bb commit 02ce0bf
Show file tree
Hide file tree
Showing 27 changed files with 514 additions and 86 deletions.
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# shell scripts
*.sh text eol=lf

# linux Pg dist links, libs
pg-dist/pgsql-*-linux-binaries/**/lib*.so[\.\d]* binary
pg-dist/pgsql-*-linux-binaries/bin/** binary
pg-dist/pgsql-*-linux-binaries/lib/** binary
pg-dist/pgsql-*-linux-binaries/share/** binary

# windows Pg dist links, libs
pg-dist/pgsql-*-windows64-binaries/bin/** binary
pg-dist/pgsql-*-windows64-binaries/lib/** binary
pg-dist/pgsql-*-windows64-binaries/share/** binary
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.user
*.userosscache
*.sln.docstates
*.vscode

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
4 changes: 4 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ mode: ContinuousDelivery
branches:
dev(elop)?(ment)?$:
mode: ContinuousDeployment
release/*$:
mode: ContinuousDeployment
hotfix/*$:
mode: ContinuousDeployment
master:
mode: ContinuousDelivery
(pull|pull\-requests|pr)[/-]: {}
Expand Down
55 changes: 50 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,63 @@ Postgres2Go
===========
> Postgres2Go - PostgreSQL for integration tests
## Description
# Installation
# Usage
[![GitHub release][github-release-img]][github-release-url] [![Master build status][appveyor-master-status]][appveyor-project-url] [![Develop build status][appveyor-develop-status]][appveyor-project-url] [![GitHub license][license-img]][license-url]

[![Stable nuget][nuget-img]][nuget-url] [![Downloads][nuget-stats-img]][nuget-url]

### Description
>Inspired by __[https://github.com/Mongo2Go/Mongo2Go](https://github.com/Mongo2Go/Mongo2Go)__
Easily spin up PostgreSQL instances for integration tests. It targets .NET Standard 2.0, .NET 4.6, .NET 4.7. This Nuget package contains the executables of PostgreSQL for Windows, Linux.

## Installation

Using __nuget.exe__ and __powershell__:
```
Install-Package Postgres2Go
```

or using __dotnet cli__:
```
dotnet add package Postgres2Go
```

or using __paket.exe__:
```
paket add Postgres2Go
```

## Usage

Execute static factory method __`PostgresRunner.Start()`__ to setup new instance of disposable `PostgresRunner` and isolated instance of PostgreSQL.

`PostgresRunner.Start()` accepts parameters:
- `DataDirectory` directory where new instance of PostgreSQL cluster will keep its data; if not provided then special directory will be created inside of `TEMP` folder
- `BinariesSearchPattern` path part where PostgreSQL distribution should be located
- `Port` TCP port used by PostgreSQL instance; if not provided then first free TCP port above 15433 will be used

To cleanup environment execute method __`Dispose()`__

Example usage can be found under __`src/Postgres2Go.Samples`__

## Credits
Copyright (c) 2017 Johannes Hoppe
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 pg-dist folder that are distributed under [PostgreSQL License](tools/LICENSE.md)
It contains third-party files located in the pg-dist folder that are distributed under [PostgreSQL License](tools/LICENSE.md)

[appveyor-master-status]: https://ci.appveyor.com/api/projects/status/github/bt-skyrise/Postgres2Go?svg=true&branch=master&passingText=master%20pass&failingText=master%20failed
[appveyor-develop-status]: https://ci.appveyor.com/api/projects/status/github/bt-skyrise/Postgres2Go?svg=true&branch=develop&passingText=develop%20pass&failingText=develop%20failed
[appveyor-project-url]: https://ci.appveyor.com/project/skyrisetech/postgres2go
[github-release-img]: https://img.shields.io/github/release/bt-skyrise/Postgres2Go.svg
[github-release-url]: https://github.com/bt-skyrise/Postgres2Go/releases
[license-img]: https://img.shields.io/badge/License-MIT-green.svg
[license-url]: https://raw.githubusercontent.com/bt-skyrise/Postgres2Go/master/LICENSE.md
[nuget-img]: https://img.shields.io/nuget/v/Postgres2Go.svg?label=stable%20nuget
[nuget-stats-img]: https://img.shields.io/nuget/dt/Postgres2Go.svg?label=downloads
[nuget-url]:https://www.nuget.org/packages/Postgres2Go/
29 changes: 29 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ environment:
DOTNET_CLI_TELEMETRY_OPTOUT: true
VERSION_INFO_SEMVER: null
VERSION_INFO: null
VERSION_INFO_NUGET: null
nuget:
project_feed: true
disable_publish_on_pr: true
Expand All @@ -27,6 +28,8 @@ before_build:
$env:VERSION_INFO = $version_info;
$env:VERSION_INFO_SEMVER = $version_info.SemVer;
$env:VERSION_INFO_NUGET = $version_info.NuGetVersion
Update-AppveyorBuild -Version "$env:VERSION_INFO_SEMVER-$env:APPVEYOR_BUILD_NUMBER";
Expand Down Expand Up @@ -61,3 +64,29 @@ deploy:
artifact: NuGet
on:
branch: master
- provider: BinTray
username: zabrowarnyrafal
api_key:
secure: XjrCjUTd9QwNy4cUUMuFkzKj9yjWIqBc7ry9Qbqosi7y8OY4NogNFGaog6dIj98D
subject: skyrise
repo: Postgres2Go
package: Postgres2Go
version: ${VERSION_INFO_NUGET}
artifact: NuGet
publish: true
override: true
on:
branch: /hotfix\/*/
- provider: BinTray
username: zabrowarnyrafal
api_key:
secure: XjrCjUTd9QwNy4cUUMuFkzKj9yjWIqBc7ry9Qbqosi7y8OY4NogNFGaog6dIj98D
subject: skyrise
repo: Postgres2Go
package: Postgres2Go
version: ${VERSION_INFO_NUGET}
artifact: NuGet
publish: true
override: true
on:
branch: /release\/*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

declare -A PG_LIB_LINKS

PG_LIB_LINKS=(
["libpq.so"]="libpq.so.5.10" \
["libpq.so.5"]="libpq.so.5.10" \
["libpgtypes.so"]="libpgtypes.so.3.10" \
["libpgtypes.so.3"]="libpgtypes.so.3.10" \
["libicuuc.so"]="libicuuc.so.53.1" \
["libicuuc.so.53"]="libicuuc.so.53.1" \
["libicutu.so"]="libicutu.so.53.1" \
["libicutu.so.53"]="libicutu.so.53.1" \
["libicutest.so"]="libicutest.so.53.1" \
["libicutest.so.53"]="libicutest.so.53.1" \
["libiculx.so"]="libiculx.so.53.1" \
["libiculx.so.53"]="libiculx.so.53.1" \
["libicule.so"]="libicule.so.53.1" \
["libicule.so.53"]="libicule.so.53.1" \
["libicuio.so"]="libicuio.so.53.1" \
["libicuio.so.53"]="libicuio.so.53.1" \
["libicui18n.so"]="libicui18n.so.53.1" \
["libicui18n.so.53"]="libicui18n.so.53.1" \
["libicudata.so"]="libicudata.so.53.1" \
["libicudata.so.53"]="libicudata.so.53.1" \
["libecpg.so"]="libecpg.so.6.10" \
["libecpg.so.6"]="libecpg.so.6.10" \
["libecpg_compat.so"]="libecpg_compat.so.3.10" \
["libecpg_compat.so.3"]="libecpg_compat.so.3.10" \
["libcurl.so"]="libcurl.so.4.4.0" \
["libcurl.so.4"]="libcurl.so.4.4.0" \
)

PG_BINARIES="$1"

cd $PG_BINARIES
cd ./../lib

echo "Changed working_dir to $PWD"

for link in ${!PG_LIB_LINKS[@]};
do
if [[ -e $link ]] || [[ -h $link ]]
then
echo "Removing $link"
rm $link
else
echo "Not found $link"
fi

target="${PG_LIB_LINKS[$link]}"
echo "Create link $link targeting $target"
ln -s $target $link
done
14 changes: 1 addition & 13 deletions src/Postgres2Go.Samples/when_using_as_class_fixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Npgsql;
Expand All @@ -13,23 +12,12 @@ public class PgFixture : IDisposable

public PgFixture()
{
_pgRunner = PostgresRunner
.Start(new PostgresRunnerOptions{ BinariesSearchPattern = GetPgBinariesRelativePath()});
_pgRunner = PostgresRunner.Start();
}

public void Dispose() => _pgRunner?.Dispose();

public string ConnectionString => _pgRunner.GetConnectionString();

private string GetPgBinariesRelativePath()
{
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return "\\pg-dist\\pgsql-10.1-windows64-binaries\\bin";
else if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return "/pg-dist/pgsql-10.1-linux-binaries/bin";
else
throw new NotSupportedException("OSX is not yet supported");
}
}

public class when_using_as_class_fixture : IClassFixture<PgFixture>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using System;
using System.IO;
using Xunit;
using Postgres2Go.Helper.FileSystem;
using Postgres2Go.Helper.Postgres;

namespace Postgres2Go.Tests.Helpers.FolderSearch
{
public class when_invoke_FindFolderUpwards : IDisposable
{
private readonly Fixture _fixture;

public when_invoke_FindFolderUpwards()
{
_fixture = new Fixture();
}

public void Dispose()
{
_fixture?.Dispose();
}

[Theory]
[InlineData("a")]
[InlineData(@"a\b")]
[InlineData(@"a\b\c")]
[InlineData(@"a\b\c\d")]
[InlineData(@"a\b\c\d\e")]
public void should_locate_directory_with_default_search_pattern(string executionPath)
{
// PREPARE
_fixture.CreateSubDirectoryIfNotExists(
Path.Combine(@"packages\Postgres2Go-0.3.0", @"pg-dist\pgsql-10.1-windows64-binaries\bin")
);

string executionAbsPath = _fixture
.CreateSubDirectoryIfNotExists(executionPath);

string searchLocation = Path.Combine(
PostgresBinaryLocator.NugetPackagesDirectoryPrefix,
PostgresBinaryLocator.DefaultWindowsSearchPattern
);

// RUN
string foundLocation = executionAbsPath
.FindFolderUpwards(searchLocation);

// ASSERT
Assert.NotNull(foundLocation);
}

[Theory]
[InlineData("a", @"packa*\Postgres2*\pg-dist\pgsql-*\bin")]
[InlineData(@"a\b", @"packa*\Postgres2*\pg-dist\pgsql-*\bin")]
[InlineData(@"a\b\c\d\e", @"packa*\Postgres2*\pg-dist\pgsql-*\bin")]
public void should_locate_directory_using_custom_search_pattern(string executionPath, string searchPattern)
{
// PREPARE
_fixture.CreateSubDirectoryIfNotExists(
Path.Combine(@"packages\Postgres2Go-0.3.0", @"pg-dist\pgsql-10.1-windows64-binaries\bin")
);

string executionAbsPath = _fixture
.CreateSubDirectoryIfNotExists(executionPath);

// RUN
string foundLocation = executionAbsPath
.FindFolderUpwards(searchPattern);

// ASSERT
Assert.NotNull(foundLocation);
}

[Theory]
[InlineData(@"a\b\c\d\e\f")]
[InlineData(@"a\b\c\d\e\f\g")]
public void cannot_locate_directory_when_nest_level_greater_than_5(string executionPath)
{
// PREPARE
_fixture.CreateSubDirectoryIfNotExists(
Path.Combine(@"packages\Postgres2Go-0.3.0", @"pg-dist\pgsql-10.1-windows64-binaries\bin")
);

string executionAbsPath = _fixture
.CreateSubDirectoryIfNotExists(executionPath);

string searchLocation = Path.Combine(
PostgresBinaryLocator.NugetPackagesDirectoryPrefix,
PostgresBinaryLocator.DefaultWindowsSearchPattern
);

// RUN
string foundLocation = executionAbsPath
.FindFolderUpwards(searchLocation);

// ASSERT
Assert.Null(foundLocation);

}

class Fixture : IDisposable
{
internal string Root { get; private set; }

public Fixture()
{
Root = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

if (!Directory.Exists(Root))
Directory.CreateDirectory(Root);
}

public string CreateSubDirectoryIfNotExists(string path)
{
var subDirPath = Path.Combine(Root, path);

if (!Directory.Exists(subDirPath))
Directory.CreateDirectory(subDirPath);

return subDirPath;
}

public void Dispose()
{
if (!Directory.Exists(Root))
Directory.Delete(Root);
}
}
}
}

0 comments on commit 02ce0bf

Please sign in to comment.