Skip to content

Commit

Permalink
Use the interface rather than the concret type
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Jan 27, 2020
1 parent 93436c3 commit 8e1f3a2
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 35 deletions.
8 changes: 4 additions & 4 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
)

var (
dockerCli *client.Client
dockerCli client.CommonAPIClient
registryConfig *h.TestRegistryConfig
suiteManager *SuiteManager
)
Expand Down Expand Up @@ -1479,7 +1479,7 @@ func createPackage(t *testing.T, configDir, tmpDir, packPath string) string {
return packageImageName
}

func createStack(t *testing.T, dockerCli *client.Client, runImageMirror string) error {
func createStack(t *testing.T, dockerCli client.CommonAPIClient, runImageMirror string) error {
t.Helper()
t.Log("creating stack images...")

Expand All @@ -1501,7 +1501,7 @@ func createStack(t *testing.T, dockerCli *client.Client, runImageMirror string)
return nil
}

func createStackImage(dockerCli *client.Client, repoName string, dir string) error {
func createStackImage(dockerCli client.CommonAPIClient, repoName string, dir string) error {
ctx := context.Background()
buildContext := archive.ReadDirAsTar(dir, "/", 0, 0, -1)

Expand Down Expand Up @@ -1659,7 +1659,7 @@ func terminateAtStep(t *testing.T, cmd *exec.Cmd, buf *bytes.Buffer, pattern str
}
}

func imageLabel(t *testing.T, dockerCli *client.Client, repoName, labelName string) string {
func imageLabel(t *testing.T, dockerCli client.CommonAPIClient, repoName, labelName string) string {
t.Helper()
inspect, _, err := dockerCli.ImageInspectWithRaw(context.Background(), repoName)
h.AssertNil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Client struct {
imageFetcher ImageFetcher
downloader Downloader
lifecycle Lifecycle
docker *dockerClient.Client
docker dockerClient.CommonAPIClient
imageFactory ImageFactory
}

Expand Down Expand Up @@ -84,7 +84,7 @@ func WithCacheDir(path string) ClientOption {
}

// WithDockerClient supply your own docker client.
func WithDockerClient(docker *dockerClient.Client) ClientOption {
func WithDockerClient(docker dockerClient.CommonAPIClient) ClientOption {
return func(c *Client) {
c.docker = docker
}
Expand Down
4 changes: 2 additions & 2 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
type Lifecycle struct {
builder *builder.Builder
logger logging.Logger
docker *client.Client
docker client.CommonAPIClient
appPath string
appOnce *sync.Once
httpProxy string
Expand All @@ -46,7 +46,7 @@ func init() {
rand.Seed(time.Now().UTC().UnixNano())
}

func NewLifecycle(docker *client.Client, logger logging.Logger) *Lifecycle {
func NewLifecycle(docker client.CommonAPIClient, logger logging.Logger) *Lifecycle {
return &Lifecycle{logger: logger, docker: docker}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/build/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
type Phase struct {
name string
logger logging.Logger
docker *client.Client
docker client.CommonAPIClient
ctrConf *dcontainer.Config
hostConf *dcontainer.HostConfig
ctr dcontainer.ContainerCreateCreatedBody
Expand Down
6 changes: 3 additions & 3 deletions internal/build/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

var (
repoName string
dockerCli *client.Client
dockerCli client.CommonAPIClient
)

func TestPhase(t *testing.T) {
Expand Down Expand Up @@ -56,7 +56,7 @@ func testPhase(t *testing.T, when spec.G, it spec.S) {
var (
subject *build.Lifecycle
outBuf, errBuf bytes.Buffer
docker *client.Client
docker client.CommonAPIClient
)

it.Before(func() {
Expand Down Expand Up @@ -333,7 +333,7 @@ func assertRunSucceeds(t *testing.T, phase *build.Phase, outBuf *bytes.Buffer, e
phase.Cleanup()
}

func CreateFakeLifecycle(appDir string, docker *client.Client, logger logging.Logger) (*build.Lifecycle, error) {
func CreateFakeLifecycle(appDir string, docker client.CommonAPIClient, logger logging.Logger) (*build.Lifecycle, error) {
subject := build.NewLifecycle(docker, logger)
builderImage, err := local.NewImage(repoName, docker, local.FromBaseImage(repoName))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/image_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
)

type ImageCache struct {
docker *client.Client
docker client.CommonAPIClient
image string
}

func NewImageCache(imageRef name.Reference, dockerClient *client.Client) *ImageCache {
func NewImageCache(imageRef name.Reference, dockerClient client.CommonAPIClient) *ImageCache {
sum := sha256.Sum256([]byte(imageRef.Name()))
return &ImageCache{
image: fmt.Sprintf("pack-cache-%x", sum[:6]),
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/image_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestImageCache(t *testing.T) {

func testImageCache(t *testing.T, when spec.G, it spec.S) {
when("#NewImageCache", func() {
var dockerClient *client.Client
var dockerClient client.CommonAPIClient

it.Before(func() {
var err error
Expand Down Expand Up @@ -100,7 +100,7 @@ func testImageCache(t *testing.T, when spec.G, it spec.S) {
when("#Clear", func() {
var (
imageName string
dockerClient *client.Client
dockerClient client.CommonAPIClient
subject *cache.ImageCache
ctx context.Context
)
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/volume_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
)

type VolumeCache struct {
docker *client.Client
docker client.CommonAPIClient
volume string
}

func NewVolumeCache(imageRef name.Reference, suffix string, dockerClient *client.Client) *VolumeCache {
func NewVolumeCache(imageRef name.Reference, suffix string, dockerClient client.CommonAPIClient) *VolumeCache {
sum := sha256.Sum256([]byte(imageRef.Name()))
return &VolumeCache{
volume: fmt.Sprintf("pack-cache-%x.%s", sum[:6], suffix),
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/volume_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestVolumeCache(t *testing.T) {

func testCache(t *testing.T, when spec.G, it spec.S) {
when("#NewVolumeCache", func() {
var dockerClient *client.Client
var dockerClient client.CommonAPIClient

it.Before(func() {
var err error
Expand Down Expand Up @@ -108,7 +108,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) {
when("#Clear", func() {
var (
volumeName string
dockerClient *client.Client
dockerClient client.CommonAPIClient
subject *cache.VolumeCache
ctx context.Context
)
Expand Down
2 changes: 1 addition & 1 deletion internal/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/pkg/errors"
)

func Run(ctx context.Context, docker *client.Client, ctrID string, out, errOut io.Writer) error {
func Run(ctx context.Context, docker client.CommonAPIClient, ctrID string, out, errOut io.Writer) error {
bodyChan, errChan := docker.ContainerWait(ctx, ctrID, dcontainer.WaitConditionNextExit)

if err := docker.ContainerStart(ctx, ctrID, types.ContainerStartOptions{}); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/image/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
)

type DefaultImageFactory struct {
dockerClient *client.Client
dockerClient client.CommonAPIClient
keychain authn.Keychain
}

func NewFactory(dockerClient *client.Client, keychain authn.Keychain) *DefaultImageFactory {
func NewFactory(dockerClient client.CommonAPIClient, keychain authn.Keychain) *DefaultImageFactory {
return &DefaultImageFactory{
dockerClient: dockerClient,
keychain: keychain,
Expand Down
4 changes: 2 additions & 2 deletions internal/image/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
)

type Fetcher struct {
docker *client.Client
docker client.CommonAPIClient
logger logging.Logger
}

func NewFetcher(logger logging.Logger, docker *client.Client) *Fetcher {
func NewFetcher(logger logging.Logger, docker client.CommonAPIClient) *Fetcher {
return &Fetcher{
logger: logger,
docker: docker,
Expand Down
2 changes: 1 addition & 1 deletion internal/image/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
h "github.com/buildpacks/pack/testhelpers"
)

var docker *client.Client
var docker client.CommonAPIClient
var registryConfig *h.TestRegistryConfig

func TestFetcher(t *testing.T) {
Expand Down
18 changes: 9 additions & 9 deletions testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ func hasMatches(actual, exp string) bool {
return len(matches) > 0
}

var dockerCliVal *client.Client
var dockerCliVal client.CommonAPIClient
var dockerCliOnce sync.Once
var dockerCliErr error

func dockerCli(t *testing.T) *client.Client {
func dockerCli(t *testing.T) client.CommonAPIClient {
dockerCliOnce.Do(func() {
dockerCliVal, dockerCliErr = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
})
Expand Down Expand Up @@ -236,7 +236,7 @@ func Eventually(t *testing.T, test func() bool, every time.Duration, timeout tim
}
}

func CreateImage(t *testing.T, dockerCli *client.Client, repoName, dockerFile string) {
func CreateImage(t *testing.T, dockerCli client.CommonAPIClient, repoName, dockerFile string) {
t.Helper()

buildContext, err := archive.CreateSingleFileTarReader("Dockerfile", dockerFile)
Expand All @@ -254,7 +254,7 @@ func CreateImage(t *testing.T, dockerCli *client.Client, repoName, dockerFile st
AssertNil(t, errors.Wrapf(err, "building image %s", style.Symbol(repoName)))
}

func CreateImageFromDir(t *testing.T, dockerCli *client.Client, repoName string, dir string) {
func CreateImageFromDir(t *testing.T, dockerCli client.CommonAPIClient, repoName string, dir string) {
t.Helper()

buildContext := archive.ReadDirAsTar(dir, "/", 0, 0, -1)
Expand Down Expand Up @@ -301,7 +301,7 @@ func checkResponse(response dockertypes.ImageBuildResponse) error {
return nil
}

func CreateImageOnRemote(t *testing.T, dockerCli *client.Client, registryConfig *TestRegistryConfig, repoName, dockerFile string) string {
func CreateImageOnRemote(t *testing.T, dockerCli client.CommonAPIClient, registryConfig *TestRegistryConfig, repoName, dockerFile string) string {
t.Helper()
imageName := registryConfig.RepoName(repoName)

Expand All @@ -311,7 +311,7 @@ func CreateImageOnRemote(t *testing.T, dockerCli *client.Client, registryConfig
return imageName
}

func DockerRmi(dockerCli *client.Client, repoNames ...string) error {
func DockerRmi(dockerCli client.CommonAPIClient, repoNames ...string) error {
var err error
ctx := context.Background()
for _, name := range repoNames {
Expand All @@ -327,7 +327,7 @@ func DockerRmi(dockerCli *client.Client, repoNames ...string) error {
return err
}

func PushImage(dockerCli *client.Client, ref string, registryConfig *TestRegistryConfig) error {
func PushImage(dockerCli client.CommonAPIClient, ref string, registryConfig *TestRegistryConfig) error {
rc, err := dockerCli.ImagePush(context.Background(), ref, dockertypes.ImagePushOptions{RegistryAuth: registryConfig.RegistryAuth()})
if err != nil {
return err
Expand Down Expand Up @@ -418,7 +418,7 @@ func RunE(cmd *exec.Cmd) (string, error) {
return string(output), nil
}

func PullImageWithAuth(dockerCli *client.Client, ref, registryAuth string) error {
func PullImageWithAuth(dockerCli client.CommonAPIClient, ref, registryAuth string) error {
rc, err := dockerCli.ImagePull(context.Background(), ref, dockertypes.ImagePullOptions{RegistryAuth: registryAuth})
if err != nil {
return nil
Expand Down Expand Up @@ -482,7 +482,7 @@ func SkipIf(t *testing.T, expression bool, reason string) {
}
}

func RunContainer(ctx context.Context, dockerCli *client.Client, id string, stdout io.Writer, stderr io.Writer) error {
func RunContainer(ctx context.Context, dockerCli client.CommonAPIClient, id string, stdout io.Writer, stderr io.Writer) error {
bodyChan, errChan := dockerCli.ContainerWait(ctx, id, container.WaitConditionNextExit)

if err := dockerCli.ContainerStart(ctx, id, dockertypes.ContainerStartOptions{}); err != nil {
Expand Down

0 comments on commit 8e1f3a2

Please sign in to comment.