mirror of https://github.com/docker/docs.git
Merge pull request #3275 from nathanleclaire/fix_rc_version_mismatch
Fix RC version mismatch bug
This commit is contained in:
commit
f6f812a95e
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/machine/libmachine/log"
|
"github.com/docker/machine/libmachine/log"
|
||||||
"github.com/docker/machine/version"
|
"github.com/docker/machine/version"
|
||||||
|
|
@ -23,6 +24,7 @@ const (
|
||||||
defaultURL = "https://api.github.com/repos/boot2docker/boot2docker/releases"
|
defaultURL = "https://api.github.com/repos/boot2docker/boot2docker/releases"
|
||||||
defaultISOFilename = "boot2docker.iso"
|
defaultISOFilename = "boot2docker.iso"
|
||||||
defaultVolumeIDOffset = int64(0x8028)
|
defaultVolumeIDOffset = int64(0x8028)
|
||||||
|
versionPrefix = "-v"
|
||||||
defaultVolumeIDLength = 32
|
defaultVolumeIDLength = 32
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -304,10 +306,19 @@ func (b *b2dISO) version() (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
verRegex := regexp.MustCompile(`v\d+\.\d+\.\d+`)
|
fullVersion := string(isoMetadata)
|
||||||
ver := string(verRegex.Find(isoMetadata))
|
|
||||||
log.Debug("local Boot2Docker ISO version: ", ver)
|
versionIndex := strings.Index(fullVersion, versionPrefix)
|
||||||
return ver, nil
|
if versionIndex == -1 {
|
||||||
|
return "", fmt.Errorf("Did not find prefix %q in version string", versionPrefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Original magic file string looks similar to this: "Boot2Docker-v0.1.0 "
|
||||||
|
// This will return "v0.1.0" given the above string
|
||||||
|
vers := strings.TrimSpace(fullVersion)[versionIndex+1:]
|
||||||
|
|
||||||
|
log.Debug("local Boot2Docker ISO version: ", vers)
|
||||||
|
return vers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeFileIfExists(name string) error {
|
func removeFileIfExists(name string) error {
|
||||||
|
|
|
||||||
|
|
@ -72,22 +72,28 @@ func TestGetReleaseURLError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVersion(t *testing.T) {
|
func TestVersion(t *testing.T) {
|
||||||
want := "v0.1.0"
|
testCases := []string{
|
||||||
isopath, off, err := newDummyISO("", defaultISOFilename, want)
|
"v0.1.0",
|
||||||
defer removeFileIfExists(isopath)
|
"v0.2.0-rc1",
|
||||||
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
b := &b2dISO{
|
|
||||||
commonIsoPath: isopath,
|
|
||||||
volumeIDOffset: off,
|
|
||||||
volumeIDLength: defaultVolumeIDLength,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := b.version()
|
for _, vers := range testCases {
|
||||||
|
isopath, off, err := newDummyISO("", defaultISOFilename, vers)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, want, string(got))
|
|
||||||
|
b := &b2dISO{
|
||||||
|
commonIsoPath: isopath,
|
||||||
|
volumeIDOffset: off,
|
||||||
|
volumeIDLength: defaultVolumeIDLength,
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := b.version()
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, vers, string(got))
|
||||||
|
removeFileIfExists(isopath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDownloadISO(t *testing.T) {
|
func TestDownloadISO(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue