Skip to content

Commit 2ecc559

Browse files
Fix RC version mismatch bug
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
1 parent 60dbecb commit 2ecc559

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

libmachine/mcnutils/b2d.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"os"
1515
"path/filepath"
1616
"regexp"
17+
"strings"
1718

1819
"github.com/docker/machine/libmachine/log"
1920
"github.com/docker/machine/version"
@@ -23,6 +24,7 @@ const (
2324
defaultURL = "https://api.github.com/repos/boot2docker/boot2docker/releases"
2425
defaultISOFilename = "boot2docker.iso"
2526
defaultVolumeIDOffset = int64(0x8028)
27+
versionPrefix = "-v"
2628
defaultVolumeIDLength = 32
2729
)
2830

@@ -304,10 +306,19 @@ func (b *b2dISO) version() (string, error) {
304306
return "", err
305307
}
306308

307-
verRegex := regexp.MustCompile(`v\d+\.\d+\.\d+`)
308-
ver := string(verRegex.Find(isoMetadata))
309-
log.Debug("local Boot2Docker ISO version: ", ver)
310-
return ver, nil
309+
fullVersion := string(isoMetadata)
310+
311+
versionIndex := strings.Index(fullVersion, versionPrefix)
312+
if versionIndex == -1 {
313+
return "", fmt.Errorf("Did not find prefix %q in version string", versionPrefix)
314+
}
315+
316+
// Original magic file string looks similar to this: "Boot2Docker-v0.1.0 "
317+
// This will return "v0.1.0" given the above string
318+
vers := strings.TrimSpace(fullVersion)[versionIndex+1:]
319+
320+
log.Debug("local Boot2Docker ISO version: ", vers)
321+
return vers, nil
311322
}
312323

313324
func removeFileIfExists(name string) error {

libmachine/mcnutils/b2d_test.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,28 @@ func TestGetReleaseURLError(t *testing.T) {
7272
}
7373

7474
func TestVersion(t *testing.T) {
75-
want := "v0.1.0"
76-
isopath, off, err := newDummyISO("", defaultISOFilename, want)
77-
defer removeFileIfExists(isopath)
75+
testCases := []string{
76+
"v0.1.0",
77+
"v0.2.0-rc1",
78+
}
7879

79-
assert.NoError(t, err)
80+
for _, vers := range testCases {
81+
isopath, off, err := newDummyISO("", defaultISOFilename, vers)
8082

81-
b := &b2dISO{
82-
commonIsoPath: isopath,
83-
volumeIDOffset: off,
84-
volumeIDLength: defaultVolumeIDLength,
85-
}
83+
assert.NoError(t, err)
8684

87-
got, err := b.version()
85+
b := &b2dISO{
86+
commonIsoPath: isopath,
87+
volumeIDOffset: off,
88+
volumeIDLength: defaultVolumeIDLength,
89+
}
8890

89-
assert.NoError(t, err)
90-
assert.Equal(t, want, string(got))
91+
got, err := b.version()
92+
93+
assert.NoError(t, err)
94+
assert.Equal(t, vers, string(got))
95+
removeFileIfExists(isopath)
96+
}
9197
}
9298

9399
func TestDownloadISO(t *testing.T) {

0 commit comments

Comments
 (0)