From e4828e807797a7641fcd457716870dfc2f9e82ff Mon Sep 17 00:00:00 2001 From: "Aeneas Rekkas (arekkas)" Date: Mon, 5 Dec 2016 22:08:48 +0100 Subject: [PATCH] core: pull images only when they are missing - closes #70 --- dockertest.go | 15 +++++++++------ dockertest_test.go | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/dockertest.go b/dockertest.go index eb9d0143..b4d7d158 100644 --- a/dockertest.go +++ b/dockertest.go @@ -70,11 +70,14 @@ func (d *Pool) Run(repository, tag string, env []string) (*Resource, error) { tag = "latest" } - if err := d.Client.PullImage(dc.PullImageOptions{ - Repository: repository, - Tag: tag, - }, dc.AuthConfiguration{}); err != nil { - return nil, errors.Wrap(err, "") + _, err := d.Client.InspectImage(fmt.Sprintf("%s:%s", repository, tag)) + if err != nil { + if err := d.Client.PullImage(dc.PullImageOptions{ + Repository: repository, + Tag: tag, + }, dc.AuthConfiguration{}); err != nil { + return nil, errors.Wrap(err, "") + } } c, err := d.Client.CreateContainer(dc.CreateContainerOptions{ @@ -121,7 +124,7 @@ func (d *Pool) Purge(r *Resource) error { // Retry is an exponential backoff retry helper. You can use it to wait for e.g. mysql to boot up. func (d *Pool) Retry(op func() error) error { if d.MaxWait == 0 { - d.MaxWait = time.Minute / 2 + d.MaxWait = time.Minute } bo := backoff.NewExponentialBackOff() bo.MaxInterval = time.Second * 5 diff --git a/dockertest_test.go b/dockertest_test.go index 5904914a..3d4c6533 100644 --- a/dockertest_test.go +++ b/dockertest_test.go @@ -25,7 +25,7 @@ func TestMain(m *testing.M) { } func TestMySQL(t *testing.T) { - resource, err := pool.Run("mysql", "5.7", []string{"MYSQL_ROOT_PASSWORD=secret"}) + resource, err := pool.Run("mysql", "5.6", []string{"MYSQL_ROOT_PASSWORD=secret"}) require.Nil(t, err) assert.NotEmpty(t, resource.GetPort("3306/tcp")) @@ -41,7 +41,7 @@ func TestMySQL(t *testing.T) { } func TestPostgres(t *testing.T) { - resource, err := pool.Run("postgres", "9.6", nil) + resource, err := pool.Run("postgres", "9.5", nil) require.Nil(t, err) assert.NotEmpty(t, resource.GetPort("5432/tcp"))