diff --git a/libmachine/mcnutils/b2d.go b/libmachine/mcnutils/b2d.go index adec9629b4..b37ef6ee79 100644 --- a/libmachine/mcnutils/b2d.go +++ b/libmachine/mcnutils/b2d.go @@ -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 { diff --git a/libmachine/mcnutils/b2d_test.go b/libmachine/mcnutils/b2d_test.go index a0cfe38e8c..cf1cfad426 100644 --- a/libmachine/mcnutils/b2d_test.go +++ b/libmachine/mcnutils/b2d_test.go @@ -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) {