Skip to content

Commit

Permalink
separate func dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroFruit authored and junbeomlee committed Sep 7, 2018
1 parent f0a3842 commit 820add6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
38 changes: 15 additions & 23 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"fmt"
"path"
"path/filepath"
"runtime"

"strings"

"docker.io/go-docker"
Expand Down Expand Up @@ -49,7 +47,8 @@ func CreateContainer(containerImage tesseract.ContainerImage, srcPath string, de
}},
}

logDirPath, err := MakeICodeLogDir(srcPath)
logDirPath := makeICodeLogPath(srcPath)
err = MakeICodeLogDir(logDirPath)
if err != nil {
return res, err
}
Expand Down Expand Up @@ -84,7 +83,7 @@ func CreateContainer(containerImage tesseract.ContainerImage, srcPath string, de
{
ReadOnly: false,
Type: mount.TypeBind,
Source: logDirPath,
Source: ConvertToSlashedPath(logDirPath),
Target: "/go/log",
},
},
Expand Down Expand Up @@ -244,46 +243,39 @@ func GetHostIpAddress() string {
return strings.Split(host.Host, ":")[0]
}

func MakeICodeLogDir(path string) (string, error) {
logDirPath := makeICodeLogPath(path)

func MakeICodeLogDir(logDirPath string) error {
_, err := os.Stat(logDirPath)
if os.IsNotExist(err) {
err := os.MkdirAll(logDirPath, 0755)
if err != nil {
return logDirPath, err
return err
}

return logDirPath, nil
return nil
}
return logDirPath, nil
return nil
}

func makeICodeLogPath(srcPath string) string {
icodeLogPath := srcPath
logDir := fmt.Sprintf("icode_%s", filepath.Base(srcPath))

if runtime.GOOS == "windows" {
icodeLogPath = ConvertToAbsPathForWindows(icodeLogPath)
}

return path.Join(icodeLogPath, "../../icode-logs", logDir)
}

func makeICodePath(srcPath string) string {
icodePath := srcPath

if runtime.GOOS == "windows" {
icodePath = ConvertToAbsPathForWindows(icodePath)
}

return icodePath
return ConvertToSlashedPath(srcPath)
}

func ConvertToAbsPathForWindows(srcPath string) string {
func ConvertToSlashedPath(srcPath string) string {
splited := strings.Split(srcPath, ":")

if len(splited) <= 1 {
return srcPath
}

driveName := strings.ToLower(splited[0])
return strings.Replace("/"+driveName+splited[1], "\\", "/", -1)

}

func makeICodeContainerName(srcPath string) string {
Expand Down
6 changes: 3 additions & 3 deletions docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ func TestIsContainerExist(t *testing.T) {
assert.Equal(t, false, exist2)
}

func TestConvertToAbsPathForWindows(t *testing.T) {
func TestConvertToSlashedPath(t *testing.T) {
if runtime.GOOS == "window" {
GOPATH := os.Getenv("GOPATH")

// when
result := docker.ConvertToAbsPathForWindows(GOPATH)
result := docker.ConvertToSlashedPath(GOPATH)
// then
assert.Equal(t, "/c", result[:2])
}
Expand All @@ -125,7 +125,7 @@ func TestMakeICodeLogDir(t *testing.T) {
targetPath := path.Join(currentPath, ".tmp", "dir1", "dir2")
docker.MakeICodeLogDir(targetPath)

_, err := os.Stat(path.Join(currentPath, ".tmp/icode-logs/icode_dir2"))
_, err := os.Stat(path.Join(currentPath, ".tmp/dir1/dir2"))

assert.Equal(t, false, os.IsNotExist(err))
}
Expand Down

0 comments on commit 820add6

Please sign in to comment.