Skip to content

Commit e9b3d0b

Browse files
lhaskinssykesm
authored andcommitted
[FAB-9879] Refactor CouchDB runner
This refactors the couchDB runner so that we can add more runners using some of the same attributes. Change-Id: I33d61bd7178f9d03ee23b87a88d16852756e9718 Signed-off-by: Latitia M Haskins <latitia.haskins@gmail.com>
1 parent e7ec7f8 commit e9b3d0b

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

Gopkg.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ignored = [
2929

3030
[[constraint]]
3131
name = "github.com/fsouza/go-dockerclient"
32-
version = "1.0.0"
32+
version = "1.2.0"
3333

3434
[[constraint]]
3535
branch = "master"

integration/runner/couchdb.go

+2-22
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,21 @@ package runner
88

99
import (
1010
"context"
11-
"encoding/base32"
1211
"fmt"
1312
"io"
1413
"net"
1514
"net/http"
1615
"os"
1716
"strconv"
18-
"strings"
1917
"sync"
2018
"time"
2119

2220
docker "github.com/fsouza/go-dockerclient"
23-
"github.com/hyperledger/fabric/common/util"
2421
"github.com/pkg/errors"
2522
"github.com/tedsuo/ifrit"
2623
)
2724

28-
const (
29-
DefaultImage = "hyperledger/fabric-couchdb:latest"
30-
DefaultStartTimeout = 30 * time.Second
31-
)
32-
33-
// A NameFunc is used to generate container names.
34-
type NameFunc func() string
35-
36-
// DefaultNamer is the default naming function.
37-
var DefaultNamer NameFunc = UniqueName
38-
39-
// UniqueName is a NamerFunc that generates base-32 enocded UUIDs for container
40-
// names.
41-
func UniqueName() string {
42-
uuid := util.GenerateBytesUUID()
43-
encoded := base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(uuid)
44-
return strings.ToLower(encoded)
45-
}
25+
const DefaultCouchDBImage = "hyperledger/fabric-couchdb:latest"
4626

4727
// CouchDB manages the execution of an instance of a dockerized CounchDB
4828
// for tests.
@@ -70,7 +50,7 @@ type CouchDB struct {
7050
// Run runs a CouchDB container. It implements the ifrit.Runner interface
7151
func (c *CouchDB) Run(sigCh <-chan os.Signal, ready chan<- struct{}) error {
7252
if c.Image == "" {
73-
c.Image = DefaultImage
53+
c.Image = DefaultCouchDBImage
7454
}
7555

7656
if c.Name == "" {

integration/runner/defaults.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package runner
8+
9+
import (
10+
"encoding/base32"
11+
"time"
12+
13+
"github.com/hyperledger/fabric/common/util"
14+
)
15+
16+
const DefaultStartTimeout = 30 * time.Second
17+
18+
// DefaultNamer is the default naming function.
19+
var DefaultNamer NameFunc = UniqueName
20+
21+
// A NameFunc is used to generate container names.
22+
type NameFunc func() string
23+
24+
// UniqueName is a NamerFunc that generates base-32 enocded UUIDs for container names.
25+
func UniqueName() string {
26+
return base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(util.GenerateBytesUUID())
27+
}

0 commit comments

Comments
 (0)