Skip to content

Commit

Permalink
[FAB-10329] Fail fast when required image missing
Browse files Browse the repository at this point in the history
The integration tests expect ccenv and third party docker images have
been pulled before the tests start. When any of these images are
missing, fail the tests quickly with a clear message.

Change-Id: If183a531c7fcee01e01191b04ccfc746dd19ffbc
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm committed May 24, 2018
1 parent fd7bc28 commit 28d14ad
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
32 changes: 32 additions & 0 deletions integration/helpers/images.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright IBM Corp All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package helpers

import (
"fmt"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

docker "github.com/fsouza/go-dockerclient"
)

func AssertImagesExist(imageNames ...string) {
dockerClient, err := docker.NewClientFromEnv()
Expect(err).NotTo(HaveOccurred())

for _, imageName := range imageNames {
images, err := dockerClient.ListImages(docker.ListImagesOptions{
Filter: imageName,
})
ExpectWithOffset(1, err).NotTo(HaveOccurred())

if len(images) != 1 {
Fail(fmt.Sprintf("missing required image: %s", imageName), 1)
}
}
}
4 changes: 2 additions & 2 deletions integration/runner/couchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/tedsuo/ifrit"
)

const DefaultCouchDBImage = "hyperledger/fabric-couchdb:latest"
const CouchDBDefaultImage = "hyperledger/fabric-couchdb:latest"

// CouchDB manages the execution of an instance of a dockerized CounchDB
// for tests.
Expand Down Expand Up @@ -50,7 +50,7 @@ type CouchDB struct {
// Run runs a CouchDB container. It implements the ifrit.Runner interface
func (c *CouchDB) Run(sigCh <-chan os.Signal, ready chan<- struct{}) error {
if c.Image == "" {
c.Image = DefaultCouchDBImage
c.Image = CouchDBDefaultImage
}

if c.Name == "" {
Expand Down
10 changes: 10 additions & 0 deletions integration/world/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

docker "github.com/fsouza/go-dockerclient"
"github.com/hyperledger/fabric/integration/helpers"
"github.com/hyperledger/fabric/integration/runner"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
Expand All @@ -21,7 +22,16 @@ type Components struct {
Paths map[string]string
}

var RequiredImages = []string{
"hyperledger/fabric-ccenv:latest",
runner.CouchDBDefaultImage,
runner.KafkaDefaultImage,
runner.ZookeeperDefaultImage,
}

func (c *Components) Build(args ...string) {
helpers.AssertImagesExist(RequiredImages...)

if c.Paths == nil {
c.Paths = map[string]string{}
}
Expand Down

0 comments on commit 28d14ad

Please sign in to comment.