Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the interface rather than the concret type #21

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acceptance/reproducibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func testReproducibility(t *testing.T, when spec.G, it spec.S) {
var (
imageName1, imageName2 string
mutateAndSave func(t *testing.T, image imgutil.Image)
dockerClient *dockerclient.Client
dockerClient dockerclient.CommonAPIClient
)

it.Before(func() {
Expand Down
8 changes: 4 additions & 4 deletions local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

type Image struct {
repoName string
docker *client.Client
docker client.CommonAPIClient
inspect types.ImageInspect
layerPaths []string
currentTempImage string
Expand Down Expand Up @@ -73,7 +73,7 @@ func FromBaseImage(imageName string) ImageOption {
}
}

func NewImage(repoName string, dockerClient *client.Client, ops ...ImageOption) (imgutil.Image, error) {
func NewImage(repoName string, dockerClient client.CommonAPIClient, ops ...ImageOption) (imgutil.Image, error) {
inspect := defaultInspect()

image := &Image{
Expand Down Expand Up @@ -451,7 +451,7 @@ func (i *Image) downloadImageOnce(imageName string) (*FileSystemLocalImage, erro
return v.(*FileSystemLocalImage), nil
}

func downloadImage(docker *client.Client, imageName string) (*FileSystemLocalImage, error) {
func downloadImage(docker client.CommonAPIClient, imageName string) (*FileSystemLocalImage, error) {
ctx := context.Background()

tarFile, err := docker.ImageSave(ctx, []string{imageName})
Expand Down Expand Up @@ -588,7 +588,7 @@ func untar(r io.Reader, dest string) error {
}
}

func inspectOptionalImage(docker *client.Client, imageName string) (types.ImageInspect, error) {
func inspectOptionalImage(docker client.CommonAPIClient, imageName string) (types.ImageInspect, error) {
var (
err error
inspect types.ImageInspect
Expand Down
2 changes: 1 addition & 1 deletion local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newTestImageName() string {
}

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

it.Before(func() {
var err error
Expand Down
4 changes: 2 additions & 2 deletions remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestRemoteImage(t *testing.T) {

func testRemoteImage(t *testing.T, when spec.G, it spec.S) {
var repoName string
var dockerClient *client.Client
var dockerClient client.CommonAPIClient

it.Before(func() {
var err error
Expand Down Expand Up @@ -863,7 +863,7 @@ func manifestLayers(t *testing.T, repoName string) []string {
return outSlice
}

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

h.AssertNil(t, h.PullImage(dockerCli, repoName))
Expand Down
18 changes: 9 additions & 9 deletions testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ func AssertNil(t *testing.T, actual interface{}) {
}
}

var dockerCliVal *dockercli.Client
var dockerCliVal dockercli.CommonAPIClient
var dockerCliOnce sync.Once

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

func CreateImageOnLocal(t *testing.T, dockerCli *dockercli.Client, repoName, dockerFile string, labels map[string]string) {
func CreateImageOnLocal(t *testing.T, dockerCli dockercli.CommonAPIClient, repoName, dockerFile string, labels map[string]string) {
ctx := context.Background()

buildContext, err := CreateSingleFileTar("Dockerfile", dockerFile)
Expand All @@ -153,7 +153,7 @@ func CreateImageOnLocal(t *testing.T, dockerCli *dockercli.Client, repoName, doc
res.Body.Close()
}

func CreateImageOnRemote(t *testing.T, dockerCli *dockercli.Client, repoName, dockerFile string, labels map[string]string) string {
func CreateImageOnRemote(t *testing.T, dockerCli dockercli.CommonAPIClient, repoName, dockerFile string, labels map[string]string) string {
t.Helper()
defer DockerRmi(dockerCli, repoName)

Expand All @@ -173,7 +173,7 @@ func CreateImageOnRemote(t *testing.T, dockerCli *dockercli.Client, repoName, do
return topLayer
}

func PullImage(dockerCli *dockercli.Client, ref string) error {
func PullImage(dockerCli dockercli.CommonAPIClient, ref string) error {
rc, err := dockerCli.ImagePull(context.Background(), ref, dockertypes.ImagePullOptions{})
if err != nil {
// Retry
Expand All @@ -188,7 +188,7 @@ func PullImage(dockerCli *dockercli.Client, ref string) error {
return rc.Close()
}

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

func CopySingleFileFromContainer(dockerCli *dockercli.Client, ctrID, path string) (string, error) {
func CopySingleFileFromContainer(dockerCli dockercli.CommonAPIClient, ctrID, path string) (string, error) {
r, _, err := dockerCli.CopyFromContainer(context.Background(), ctrID, path)
if err != nil {
return "", err
Expand All @@ -219,7 +219,7 @@ func CopySingleFileFromContainer(dockerCli *dockercli.Client, ctrID, path string
return string(b), err
}

func CopySingleFileFromImage(dockerCli *dockercli.Client, repoName, path string) (string, error) {
func CopySingleFileFromImage(dockerCli dockercli.CommonAPIClient, repoName, path string) (string, error) {
ctr, err := dockerCli.ContainerCreate(context.Background(),
&container.Config{
Image: repoName,
Expand All @@ -234,7 +234,7 @@ func CopySingleFileFromImage(dockerCli *dockercli.Client, repoName, path string)
return CopySingleFileFromContainer(dockerCli, ctr.ID, path)
}

func PushImage(dockerCli *dockercli.Client, ref string) error {
func PushImage(dockerCli dockercli.CommonAPIClient, ref string) error {
rc, err := dockerCli.ImagePush(context.Background(), ref, dockertypes.ImagePushOptions{RegistryAuth: "{}"})
if err != nil {
return err
Expand Down