Skip to content

Commit

Permalink
Merge pull request #156 from carolynvs/install-prereleases
Browse files Browse the repository at this point in the history
Support installing prereleases
  • Loading branch information
Carolyn Van Slyck authored Mar 8, 2017
2 parents 1ae304f + 5cf95c4 commit f503e8c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ validate:
-go list ./... | grep -v /vendor/ | xargs -L1 golint --set_exit_status

test: local
go test $(GOFILES_NOVENDOR)
go test -v $(GOFILES_NOVENDOR)
eval "$( ./dvm-helper --bash-completion )"
./dvm-helper/dvm-helper --version

Expand Down
2 changes: 1 addition & 1 deletion dvm-helper/dockerversion/dockerversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (version *Version) SetAsExperimental() {
}

func (version Version) ShouldUseArchivedRelease() bool {
cutoff, _ := semver.NewConstraint(">= 1.11.0")
cutoff, _ := semver.NewConstraint(">= 1.11.0-rc1")
return version.IsExperimental() || cutoff.Check(version.SemVer)
}

Expand Down
7 changes: 6 additions & 1 deletion dvm-helper/dockerversion/dockerversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func TestIsPrerelease(t *testing.T) {
var v Version

v = Parse("17.3.0-ce-rc1")
t.Log(v.SemVer.Prerelease())
assert.True(t, v.IsPrerelease(), "%s should be a prerelease", v)

v = Parse("1.12.4-rc1")
Expand All @@ -30,3 +29,9 @@ func TestIsPrerelease(t *testing.T) {
v = Parse("17.3.0-ce")
assert.False(t, v.IsPrerelease(), "%s should NOT be a prerelease", v)
}

func TestPrereleasesUseArchivedReleases(t *testing.T) {
v := Parse("v1.12.5-rc1")

assert.True(t, v.ShouldUseArchivedRelease())
}
22 changes: 16 additions & 6 deletions dvm-helper/dvm-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var githubUrlOverride string
var debug bool
var silent bool
var nocheck bool
var useAfterInstall bool = true
var useAfterInstall bool
var token string
var includePrereleases bool

Expand All @@ -49,6 +49,11 @@ const (
)

func main() {
app := makeCliApp()
app.Run(os.Args)
}

func makeCliApp() *cli.App {
app := cli.NewApp()
app.Name = "Docker Version Manager"
app.Usage = "Manage multiple versions of the Docker client"
Expand Down Expand Up @@ -222,10 +227,12 @@ func main() {
})
}

app.Run(os.Args)
return app
}

func setGlobalVars(c *cli.Context) {
useAfterInstall = true

debug = c.GlobalBool("debug")
nocheck = c.Bool("nocheck")
token = c.GlobalString("github-token")
Expand Down Expand Up @@ -410,6 +417,10 @@ func buildDownloadURL(version dockerversion.Version) string {
writeDebug("Downloading from experimental builds mirror")
mirrorURL = "https://experimental.docker.com/builds"
}
if version.IsPrerelease() {
writeDebug("Downloading from prerelease builds mirror")
mirrorURL = "https://test.docker.com/builds"
}
}

// New Docker versions are released in a zip file, vs. the old way of releasing the client binary only
Expand Down Expand Up @@ -734,6 +745,9 @@ func getDockerVersion(dockerPath string, includeBuild bool) (dockerversion.Versi
func listRemote(prefix string) {
versions := getAvailableVersions(prefix)
for _, version := range versions {
if !includePrereleases && version.IsPrerelease() {
continue
}
writeInfo(version.String())
}
}
Expand Down Expand Up @@ -801,10 +815,6 @@ func getAvailableVersions(pattern string) []dockerversion.Version {
continue
}

if !includePrereleases && v.IsPrerelease() {
continue
}

if strings.HasPrefix(v.SemVer.String(), pattern) {
results = append(results, v)
}
Expand Down
54 changes: 41 additions & 13 deletions dvm-helper/dvm-helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,62 +74,90 @@ func TestDetectOldVersion(t *testing.T) {
os.Setenv("DOCKER_TLS_VERIFY", "0")
os.Unsetenv("DOCKER_CERT_PATH")

debug = true
outputCapture := &bytes.Buffer{}
color.Output = outputCapture

dvm := makeCliApp()
dvm.Run([]string{"dvm", "--debug", "detect"})

detect()
version := os.Getenv("DOCKER_VERSION")
assert.Equal(t, version, "1.10.3")
assert.Equal(t, version, "1.10.3", "Detected the wrong version")

output := outputCapture.String()
assert.NotEmpty(t, output, "Should have captured stdout")
assert.Contains(t, output, "Detected client version: 1.10.3", "Should have printed the detected version")
}

func TestDetectVersion(t *testing.T) {
docker, github := createMockDVM(docker1_12_1_Handler)
defer docker.Close()
defer github.Close()

outputCapture := &bytes.Buffer{}
color.Output = outputCapture

os.Setenv("DOCKER_HOST", docker.URL)
os.Setenv("DOCKER_TLS_VERIFY", "0")
os.Unsetenv("DOCKER_CERT_PATH")

debug = true
dvm := makeCliApp()
dvm.Run([]string{"dvm", "--debug", "detect"})

detect()
version := os.Getenv("DOCKER_VERSION")
assert.Equal(t, version, "1.12.1")
assert.Equal(t, version, "1.12.1", "Detected the wrong version")

output := outputCapture.String()
assert.NotEmpty(t, output, "Should have captured stdout")
assert.Contains(t, output, "Detected client version: 1.12.1", "Should have printed the detected version")
}

func TestList(t *testing.T) {
func TestListRemote(t *testing.T) {
_, github := createMockDVM(nil)
defer github.Close()

debug = true
outputCapture := &bytes.Buffer{}
color.Output = outputCapture

listRemote("1.12")
dvm := makeCliApp()
dvm.Run([]string{"dvm", "--debug", "list-remote", "1.12"})

output := outputCapture.String()
assert.NotEmpty(t, output, "Should have captured stdout")
assert.NotContains(t, output, "1.12.5-rc1", "Should not have listed a prerelease version")

}

func TestListWithPrereleases(t *testing.T) {
func TestListRemoteWithPrereleases(t *testing.T) {
_, github := createMockDVM(nil)
defer github.Close()

debug = true
includePrereleases = true
outputCapture := &bytes.Buffer{}
color.Output = outputCapture

listRemote("1.12")
dvm := makeCliApp()
dvm.Run([]string{"dvm-helper", "--debug", "list-remote", "--pre", "1.12"})

output := outputCapture.String()
assert.NotEmpty(t, output, "Should have captured stdout")
assert.Contains(t, output, "1.12.5-rc1", "Should have listed a prerelease version")

}

func TestInstallPrereleases(t *testing.T) {
_, github := createMockDVM(nil)
defer github.Close()

outputCapture := &bytes.Buffer{}
color.Output = outputCapture

dvm := makeCliApp()
dvm.Run([]string{"dvm-helper", "--debug", "install", "1.12.5-rc1"})

output := outputCapture.String()
assert.NotEmpty(t, output, "Should have captured stdout")
assert.Contains(t, output, "Now using Docker 1.12.5-rc1", "Should have installed a prerelease version")
}

func loadTestData(src string) string {
pwd, err := os.Getwd()
if err != nil {
Expand Down

0 comments on commit f503e8c

Please sign in to comment.