Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #211 from vania-pooh/master
Browse files Browse the repository at this point in the history
Better processing complex browser versions specification (fixes #208,…
  • Loading branch information
vania-pooh authored Dec 20, 2018
2 parents e1af203 + 2c715c3 commit 757bed4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
22 changes: 22 additions & 0 deletions docs/selenoid-commands.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,25 @@ An alternative to downloading `cm` manually is using Docker container:
----
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v ${HOME}:/root -e OVERRIDE_HOME=${HOME} aerokube/cm:latest-release selenoid start
----

=== Downloading Only Some Browser Versions

By default CM downloads browser images corresponding to 2 last versions of Firefox, Chrome and Opera. To download concrete browser versions - use `--browsers` flag as follows:

.Download concrete versions of Firefox and Chrome
[source,bash]
----
./cm selenoid start --browsers 'firefox:51.0;firefox:55.0;chrome:66.0'
----

.Download a range of Firefox versions and 3 last Opera versions
[source,bash]
----
./cm selenoid start --browsers 'firefox:>51.0,<=55.0;opera' --last-versions 3
----

.Download Android image (not downloaded by default because of image size)
[source,bash]
----
./cm selenoid start --browsers 'android:6.0'
----
40 changes: 22 additions & 18 deletions selenoid/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,30 +355,32 @@ func (c *DockerConfigurator) createConfig() SelenoidConfig {
return browsers
}

func parseRequestedBrowsers(logger *Logger, requestedBrowsers string) map[string]*ver.Constraints {
ret := make(map[string]*ver.Constraints)
func parseRequestedBrowsers(logger *Logger, requestedBrowsers string) map[string][]ver.Constraints {
ret := make(map[string][]ver.Constraints)
if requestedBrowsers != "" {
for _, section := range strings.Split(requestedBrowsers, semicolon) {
pieces := strings.Split(section, colon)
if len(pieces) == 2 {
browserName := pieces[0]
versionConstraintString := pieces[1]
versionConstraint, err := ver.NewConstraint(versionConstraintString)
if err != nil {
logger.Errorf(`Invalid version constraint %s: %v - ignoring browser "%s"...`, versionConstraintString, err, browserName)
continue
if len(pieces) >= 1 {
browserName := strings.TrimSpace(pieces[0])
if _, ok := ret[browserName]; !ok {
ret[browserName] = []ver.Constraints{}
}
if len(pieces) == 2 {
versionConstraintString := strings.TrimSpace(pieces[1])
versionConstraint, err := ver.NewConstraint(versionConstraintString)
if err != nil {
logger.Errorf(`Invalid version constraint %s: %v - ignoring browser "%s"...`, versionConstraintString, err, browserName)
continue
}
ret[browserName] = append(ret[browserName], versionConstraint)
}
ret[browserName] = &versionConstraint
} else if len(pieces) == 1 {
browserName := pieces[0]
ret[browserName] = nil
}
}
}
return ret
}

func (c *DockerConfigurator) getBrowsersToIterate(requestedBrowsers map[string]*ver.Constraints) map[string]string {
func (c *DockerConfigurator) getBrowsersToIterate(requestedBrowsers map[string][]ver.Constraints) map[string]string {
defaultBrowsers := map[string]string{
"firefox": "selenoid/firefox",
"chrome": "selenoid/chrome",
Expand Down Expand Up @@ -430,17 +432,19 @@ func filterOutLatest(tags []string) []string {
return ret
}

func (c *DockerConfigurator) filterTags(tags []string, versionConstraint *ver.Constraints) []string {
if versionConstraint != nil {
func (c *DockerConfigurator) filterTags(tags []string, versionConstraints []ver.Constraints) []string {
if len(versionConstraints) > 0 {
var ret []string
for _, tag := range tags {
version, err := ver.NewVersion(tag)
if err != nil {
c.Errorf("Skipping tag %s as it does not follow semantic versioning: %v", tag, err)
continue
}
if versionConstraint.Check(version) {
ret = append(ret, tag)
for _, vc := range versionConstraints {
if vc.Check(version) {
ret = append(ret, tag)
}
}
}
return ret
Expand Down
19 changes: 19 additions & 0 deletions selenoid/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,22 @@ func TestValidEnviron(t *testing.T) {
AssertThat(t, validateEnviron([]string{"=::=::"}), EqualTo{[]string{}})
AssertThat(t, validateEnviron([]string{"HOMEDRIVE=C:", "DOCKER_HOST=192.168.0.1", "=::=::"}), EqualTo{[]string{"HOMEDRIVE=C:", "DOCKER_HOST=192.168.0.1"}})
}

func TestParseRequestedBrowsers(t *testing.T) {
output := parseRequestedBrowsers(&Logger{}, "firefox:>45.0,51.0;opera; android:7.1;firefox:<50.0")
AssertThat(t, len(output), EqualTo{3})

ff, ok := output["firefox"]
AssertThat(t, ok, Is{true})
AssertThat(t, ff, Not{nil})
AssertThat(t, len(ff), EqualTo{2})

opera, ok := output["opera"]
AssertThat(t, ok, Is{true})
AssertThat(t, len(opera), EqualTo{0})

android, ok := output["android"]
AssertThat(t, ok, Is{true})
AssertThat(t, android, Not{nil})
AssertThat(t, len(android), EqualTo{1})
}

0 comments on commit 757bed4

Please sign in to comment.