Fix RC version mismatch bug
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/machine/libmachine/log"
|
||||
"github.com/docker/machine/version"
|
||||
@@ -23,6 +24,7 @@ const (
|
||||
defaultURL = "https://api.github.com/repos/boot2docker/boot2docker/releases"
|
||||
defaultISOFilename = "boot2docker.iso"
|
||||
defaultVolumeIDOffset = int64(0x8028)
|
||||
versionPrefix = "-v"
|
||||
defaultVolumeIDLength = 32
|
||||
)
|
||||
|
||||
@@ -304,10 +306,19 @@ func (b *b2dISO) version() (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
verRegex := regexp.MustCompile(`v\d+\.\d+\.\d+`)
|
||||
ver := string(verRegex.Find(isoMetadata))
|
||||
log.Debug("local Boot2Docker ISO version: ", ver)
|
||||
return ver, nil
|
||||
fullVersion := string(isoMetadata)
|
||||
|
||||
versionIndex := strings.Index(fullVersion, versionPrefix)
|
||||
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 {
|
||||
|
||||
@@ -72,22 +72,28 @@ func TestGetReleaseURLError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
want := "v0.1.0"
|
||||
isopath, off, err := newDummyISO("", defaultISOFilename, want)
|
||||
defer removeFileIfExists(isopath)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
b := &b2dISO{
|
||||
commonIsoPath: isopath,
|
||||
volumeIDOffset: off,
|
||||
volumeIDLength: defaultVolumeIDLength,
|
||||
testCases := []string{
|
||||
"v0.1.0",
|
||||
"v0.2.0-rc1",
|
||||
}
|
||||
|
||||
got, err := b.version()
|
||||
for _, vers := range testCases {
|
||||
isopath, off, err := newDummyISO("", defaultISOFilename, vers)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, want, string(got))
|
||||
assert.NoError(t, err)
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user