Refactor OS Specific code

And introduce Per-OS testing

Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
This commit is contained in:
Jean-Laurent de Morlhon 2015-11-24 16:00:19 +01:00
parent 798217fb10
commit 84a40bcc06
6 changed files with 40 additions and 12 deletions

View File

@ -372,18 +372,7 @@ func (d *Driver) Create() error {
return err
}
var shareName, shareDir string // TODO configurable at some point
switch runtime.GOOS {
case "windows":
shareName = "c/Users"
shareDir = "c:\\Users"
case "darwin":
shareName = "Users"
shareDir = "/Users"
case "linux":
shareName = "hosthome"
shareDir = "/home"
}
shareName, shareDir := getShareDriveAndName()
if shareDir != "" && !d.NoShare {
log.Debugf("setting up shareDir")

View File

@ -24,3 +24,7 @@ func (d *Driver) IsVTXDisabled() bool {
func detectVBoxManageCmd() string {
return detectVBoxManageCmdInPath()
}
func getShareDriveAndName() (string, string) {
return "Users", "/Users"
}

View File

@ -0,0 +1,14 @@
package virtualbox
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestShareName(t *testing.T) {
name, dir := getShareDriveAndName()
assert.Equal(t, name, "Users")
assert.Equal(t, dir, "/Users")
}

View File

@ -34,3 +34,7 @@ func (d *Driver) IsVTXDisabled() bool {
func detectVBoxManageCmd() string {
return detectVBoxManageCmdInPath()
}
func getShareDriveAndName() (string, string) {
return "hosthome", "/home"
}

View File

@ -0,0 +1,13 @@
package virtualbox
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestShareName(t *testing.T) {
name, dir := getShareDriveAndName()
assert.Equal(t, name, "hosthome")
assert.Equal(t, dir, "/home")
}

View File

@ -89,3 +89,7 @@ func findVBoxInstallDirInRegistry() (string, error) {
return installDir, nil
}
func getShareDriveAndName() (string, string) {
return "c/Users", "c:\\Users"
}