Skip to content

Commit

Permalink
feat(image): custom docker host option: windows compatible custom hos…
Browse files Browse the repository at this point in the history
…t test (#2997)
  • Loading branch information
aswath-s-tw committed Feb 16, 2023
1 parent 1d43274 commit 8387700
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions pkg/fanal/image/daemon/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -73,26 +74,38 @@ func Test_image_ConfigName(t *testing.T) {
}

func Test_image_ConfigNameWithCustomDockerHost(t *testing.T) {
runtimeDir, err := ioutil.TempDir("", "daemon")
require.NoError(t, err)

dir := filepath.Join(runtimeDir, "image")
err = os.MkdirAll(dir, os.ModePerm)
ref, err := name.ParseReference("alpine:3.11")
require.NoError(t, err)

customDockerHost := filepath.Join(dir, "image-test-unix-socket.sock")
eo := engine.Option{
APIVersion: opt.APIVersion,
ImagePaths: opt.ImagePaths,
}

var dockerHostParam string

if runtime.GOOS != "windows" {
runtimeDir, err := ioutil.TempDir("", "daemon")
require.NoError(t, err)

dir := filepath.Join(runtimeDir, "image")
err = os.MkdirAll(dir, os.ModePerm)
require.NoError(t, err)

te := engine.NewDockerEngine(engine.Option{
APIVersion: opt.APIVersion,
ImagePaths: opt.ImagePaths,
UnixDomainSocket: customDockerHost,
})
customDockerHost := filepath.Join(dir, "image-test-unix-socket.sock")
eo.UnixDomainSocket = customDockerHost
dockerHostParam = "unix://" + customDockerHost
}

te := engine.NewDockerEngine(eo)
defer te.Close()

ref, err := name.ParseReference("alpine:3.11")
require.NoError(t, err)
if runtime.GOOS == "windows" {
dockerHostParam = te.Listener.Addr().String()
}

img, cleanup, err := DockerImage(ref, "unix:///"+customDockerHost)
img, cleanup, err := DockerImage(ref, dockerHostParam)
require.NoError(t, err)
defer cleanup()

Expand Down

0 comments on commit 8387700

Please sign in to comment.