Skip to content

Commit

Permalink
Merge pull request #16 from vania-pooh/master
Browse files Browse the repository at this point in the history
Better Selenoid image matching (fixes #15)
  • Loading branch information
aandryashin authored Jun 6, 2017
2 parents 28aeb37 + dbdd6c3 commit 2af7de5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
12 changes: 8 additions & 4 deletions selenoid/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/heroku/docker-registry-client/registry"
"strconv"
"strings"
"time"
. "vbom.ml/util/sortorder"
"strconv"
)

const (
Expand Down Expand Up @@ -112,8 +112,12 @@ func (c *DockerConfigurator) getSelenoidImage() *types.ImageSummary {
return nil
}
for _, img := range images {
if len(img.RepoTags) > 0 && strings.Contains(img.RepoTags[0], selenoidImage) {
return &img
const colon = ":"
if len(img.RepoTags) > 0 {
imageName := strings.Split(img.RepoTags[0], colon)[0]
if imageName == selenoidImage {
return &img
}
}
}
return nil
Expand Down Expand Up @@ -362,7 +366,7 @@ func (c *DockerConfigurator) Start() error {
ExposedPorts: exposedPorts,
},
&container.HostConfig{
Binds: volumes,
Binds: volumes,
PortBindings: portBindings,
},
&network.NetworkingConfig{}, selenoidContainerName)
Expand Down
40 changes: 28 additions & 12 deletions selenoid/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

var (
mockDockerServer *httptest.Server
imageName = selenoidImage
)

func init() {
Expand Down Expand Up @@ -55,12 +56,12 @@ func mux() http.Handler {
mux.HandleFunc("/v1.29/images/json", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
output := `
output := fmt.Sprintf(`
[{
"Id": "sha256:e216a057b1cb1efc11f8a268f37ef62083e70b1b38323ba252e25ac88904a7e8",
"ParentId": "",
"RepoTags": [ "aerokube/selenoid" ],
"RepoTags": [ "%s:latest" ],
"RepoDigests": [],
"Created": 1474925151,
"Size": 103579269,
Expand All @@ -70,7 +71,7 @@ func mux() http.Handler {
"Containers": 2
}]
`
`, imageName)
w.Write([]byte(output))
},
))
Expand Down Expand Up @@ -189,13 +190,13 @@ func testConfigure(t *testing.T, download bool) {
withTmpDir(t, "test-docker-configure", func(t *testing.T, dir string) {

lcConfig := LifecycleConfig{
ConfigDir: dir,
RegistryUrl: mockDockerServer.URL,
Download: download,
Quiet: false,
ConfigDir: dir,
RegistryUrl: mockDockerServer.URL,
Download: download,
Quiet: false,
LastVersions: 2,
Tmpfs: 512,
Browsers: "firefox,opera",
Tmpfs: 512,
Browsers: "firefox,opera",
}
c, err := NewDockerConfigurator(&lcConfig)
AssertThat(t, err, Is{nil})
Expand Down Expand Up @@ -260,12 +261,27 @@ func TestStartStopContainer(t *testing.T) {
func TestDownload(t *testing.T) {
c, err := NewDockerConfigurator(&LifecycleConfig{
RegistryUrl: mockDockerServer.URL,
Quiet: true,
Version: Latest,
Quiet: true,
Version: Latest,
})
AssertThat(t, c.IsDownloaded(), Is{true})
AssertThat(t, err, Is{nil})
ref, err := c.Download()
AssertThat(t, ref, Not{nil})
AssertThat(t, err, Is{nil})
}
}

func TestGetSelenoidImage(t *testing.T) {
defer func() {
imageName = selenoidImage
}()
c, err := NewDockerConfigurator(&LifecycleConfig{
RegistryUrl: mockDockerServer.URL,
Quiet: true,
Version: Latest,
})
AssertThat(t, err, Is{nil})
AssertThat(t, c.getSelenoidImage() == nil, Is{false})
imageName = "aerokube/selenoid-ui"
AssertThat(t, c.getSelenoidImage() == nil, Is{true})
}

0 comments on commit 2af7de5

Please sign in to comment.