From 5f39eb20da16c7e038e2497aaac58aab3d0b9404 Mon Sep 17 00:00:00 2001 From: Patric Vormstein Date: Tue, 12 Mar 2019 14:08:24 +0100 Subject: [PATCH 1/3] remove postgres image tag constants --- pkg/dockertestwrapper/postgres.go | 12 ++++----- pkg/dockertestwrapper/postgres_integr_test.go | 27 ++++++++----------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/pkg/dockertestwrapper/postgres.go b/pkg/dockertestwrapper/postgres.go index 092fa98..5c1a61d 100644 --- a/pkg/dockertestwrapper/postgres.go +++ b/pkg/dockertestwrapper/postgres.go @@ -10,12 +10,6 @@ import ( // PostgresImageName is the image name of the postgres docker image const PostgresImageName string = "postgres" -// Possible postgres image versions -const ( - PostgresImageVersion10 string = "10" - PostgresImageVersion11 string = "11" -) - // Default postgres connection details const ( DefaultPostgresPort string = "5432/tcp" @@ -24,6 +18,12 @@ const ( DefaultPostgresDatabase string = "postgres" ) +var postgresImageTags = map[string]string{ + "11": "11", + "10": "10", + "9.6": "9.6", +} + // InitPostgresContainer starts a postgres container with the given tag and the default credentials func InitPostgresContainer(tag string) (*WrapperInstance, error) { userEnv := fmt.Sprintf("POSTGRES_USER=%s", DefaultPostgresUser) diff --git a/pkg/dockertestwrapper/postgres_integr_test.go b/pkg/dockertestwrapper/postgres_integr_test.go index 34ce702..c7437e3 100644 --- a/pkg/dockertestwrapper/postgres_integr_test.go +++ b/pkg/dockertestwrapper/postgres_integr_test.go @@ -1,27 +1,22 @@ package dockertestwrapper import ( + "fmt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "testing" ) func TestInitPostgresContainer(t *testing.T) { - t.Run("should start and purge a postgres 11 container successfully", func(t *testing.T) { - wrapper, err := InitPostgresContainer(PostgresImageVersion11) - assert.NoError(t, err) - require.NotNil(t, wrapper) + for postgresVersion, postgresTag := range postgresImageTags { + it := fmt.Sprintf("should start and purge a postgres %s container successfully", postgresVersion) + t.Run(it, func(t *testing.T) { + wrapper, err := InitPostgresContainer(postgresTag) + assert.NoError(t, err) + require.NotNil(t, wrapper) - err = wrapper.PurgeContainer() - assert.NoError(t, err) - }) - - t.Run("should start and purge a postgres 10 container successfully", func(t *testing.T) { - wrapper, err := InitPostgresContainer(PostgresImageVersion10) - assert.NoError(t, err) - require.NotNil(t, wrapper) - - err = wrapper.PurgeContainer() - assert.NoError(t, err) - }) + err = wrapper.PurgeContainer() + assert.NoError(t, err) + }) + } } From 204f86dbed67d324256f6cb5f6a9f53363120156 Mon Sep 17 00:00:00 2001 From: Patric Vormstein Date: Tue, 12 Mar 2019 14:12:53 +0100 Subject: [PATCH 2/3] move postgres versions into test --- pkg/dockertestwrapper/postgres.go | 6 ------ pkg/dockertestwrapper/postgres_integr_test.go | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/dockertestwrapper/postgres.go b/pkg/dockertestwrapper/postgres.go index 5c1a61d..0c655a7 100644 --- a/pkg/dockertestwrapper/postgres.go +++ b/pkg/dockertestwrapper/postgres.go @@ -18,12 +18,6 @@ const ( DefaultPostgresDatabase string = "postgres" ) -var postgresImageTags = map[string]string{ - "11": "11", - "10": "10", - "9.6": "9.6", -} - // InitPostgresContainer starts a postgres container with the given tag and the default credentials func InitPostgresContainer(tag string) (*WrapperInstance, error) { userEnv := fmt.Sprintf("POSTGRES_USER=%s", DefaultPostgresUser) diff --git a/pkg/dockertestwrapper/postgres_integr_test.go b/pkg/dockertestwrapper/postgres_integr_test.go index c7437e3..7471ca3 100644 --- a/pkg/dockertestwrapper/postgres_integr_test.go +++ b/pkg/dockertestwrapper/postgres_integr_test.go @@ -7,6 +7,12 @@ import ( "testing" ) +var postgresImageTags = map[string]string{ + "11": "11-alpine", + "10": "10-alpine", + "9.6": "9.6-alpine", +} + func TestInitPostgresContainer(t *testing.T) { for postgresVersion, postgresTag := range postgresImageTags { it := fmt.Sprintf("should start and purge a postgres %s container successfully", postgresVersion) From 9007ca64cf92fd28b4e6bbce7d7c0b38f90ae67e Mon Sep 17 00:00:00 2001 From: Patric Vormstein Date: Tue, 12 Mar 2019 14:13:19 +0100 Subject: [PATCH 3/3] update readme --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d361394..6f62594 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # dockertestwrapper [![Build Status](https://travis-ci.org/pvormste/dockertestwrapper.svg?branch=master)](https://travis-ci.org/pvormste/dockertestwrapper) -As the name suggests dockertestwrapper is a wrapper for orys awesome [dockertest library](https://github.com/ory/dockertest). +As the name suggests dockertestwrapper is a wrapper for [orys awesome dockertest library](https://github.com/ory/dockertest). It provides an easy to use api to be used in your integration tests. ## Usage @@ -11,8 +11,9 @@ The postgres helper function can be used to start a postgres container with defa Although it should be possible to start any postgres version with the `InitPostgresContainer` function, following images are covered by tests in this repository: - - postgres:11 - - postgres:10 + - postgres:11-alpine + - postgres:10-alpine + - postgres:9.6-alpine #### Connection details