Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2359 from dgageot/test-vbox-version
Browse files Browse the repository at this point in the history
Reject VirtualBox version<=3
  • Loading branch information
nathanleclaire committed Nov 20, 2015
2 parents 5918bd1 + 8d47fe7 commit c249659
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/drivers/virtualbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parent="smn_machine_drivers"

# Oracle VirtualBox
Create machines locally using [VirtualBox](https://www.virtualbox.org/).
This driver requires VirtualBox to be installed on your host.
This driver requires VirtualBox 4+ to be installed on your host.

$ docker-machine create --driver=virtualbox vbox-test

Expand Down
8 changes: 8 additions & 0 deletions drivers/virtualbox/vbm.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,11 @@ func (v *VBoxCmdManager) vbmOutErr(args ...string) (string, string, error) {

return stdout.String(), stderrStr, err
}

func checkVBoxManageVersion(version string) error {
if !strings.HasPrefix(version, "5.") && !strings.HasPrefix(version, "4.") {
return fmt.Errorf("We support Virtualbox starting with version 4. Your VirtualBox install is %q. Please upgrade at https://www.virtualbox.org", version)
}

return nil
}
42 changes: 42 additions & 0 deletions drivers/virtualbox/vbm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package virtualbox

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCheckVBoxManageVersionValid(t *testing.T) {
var tests = []struct {
version string
}{
{"5.0.8r103449"},
{"5.0"},
{"5.1"},
{"4.1"},
{"4.2.0"},
{"4.3.1"},
}

for _, test := range tests {
err := checkVBoxManageVersion(test.version)

assert.NoError(t, err)
}
}

func TestCheckVBoxManageVersionInvalid(t *testing.T) {
var tests = []struct {
version string
expectedError string
}{
{"3.9", `We support Virtualbox starting with version 4. Your VirtualBox install is "3.9". Please upgrade at https://www.virtualbox.org`},
{"", `We support Virtualbox starting with version 4. Your VirtualBox install is "". Please upgrade at https://www.virtualbox.org`},
}

for _, test := range tests {
err := checkVBoxManageVersion(test.version)

assert.EqualError(t, err, test.expectedError)
}
}
8 changes: 7 additions & 1 deletion drivers/virtualbox/virtualbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
// PreCreateCheck checks that VBoxManage exists and works
func (d *Driver) PreCreateCheck() error {
// Check that VBoxManage exists and works
if err := d.vbm(); err != nil {
version, err := d.vbmOut("--version")
if err != nil {
return err
}

// Check that VBoxManage is of a supported version
if err = checkVBoxManageVersion(version); err != nil {
return err
}

Expand Down

0 comments on commit c249659

Please sign in to comment.