Skip to content

Commit

Permalink
fix pathToFileURL in windows
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Molina <[email protected]>
  • Loading branch information
erizocosmico committed Jul 12, 2017
1 parent 6fce6fe commit db3e1bc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ install:
- mkdir -p $GOPATH/src/gopkg.in/src-d
- mv $PWD $GOPATH/src/gopkg.in/src-d/go-kallax.v1
- cd $GOPATH/src/gopkg.in/src-d/go-kallax.v1
- go get -v -t .
- go get -v -t ./generator/...
- go get -v -t ./...

script:
- make test
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ test:
tail -n +2 $(COVERAGE_PROFILE) >> $(COVERAGE_REPORT); \
rm $(COVERAGE_PROFILE); \
fi; \
for dir in `find . -name "*.go" | grep -o '.*/' | sort -u | grep -v './tests/' | grep -v './fixtures/' | grep -v './benchmarks/'`; do \
go test $$dir -coverprofile=$(COVERAGE_PROFILE) -covermode=$(COVERAGE_MODE); \
for dir in `go list ./... | grep -v '/tests' | grep -v '/fixtures' | grep -v '/benchmarks'`; do \
go test -v $$dir -coverprofile=$(COVERAGE_PROFILE) -covermode=$(COVERAGE_MODE); \
if [ $$? != 0 ]; then \
exit 2; \
fi; \
Expand Down
12 changes: 7 additions & 5 deletions generator/cli/kallax/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"path/filepath"
"strings"

"github.com/mattes/migrate"
_ "github.com/mattes/migrate/database/postgres"
Expand Down Expand Up @@ -157,11 +156,14 @@ func runMigrationAction(fn runMigrationFunc) cli.ActionFunc {
}

func pathToFileURL(path string) string {
path = strings.Replace(path, "\\", "/", -1)
if !strings.HasPrefix(path, "/") {
path = "/" + path
if !filepath.IsAbs(path) {
var err error
path, err = filepath.Abs(path)
if err != nil {
return ""
}
}
return fmt.Sprintf("file://%s", path)
return fmt.Sprintf("file://%s", filepath.ToSlash(path))
}

func migrateAction(c *cli.Context) error {
Expand Down
9 changes: 8 additions & 1 deletion generator/cli/kallax/cmd/migrate_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
// +build !windows

package cmd

import (
"os"
"path/filepath"
"testing"

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

func TestPathToFileURL(t *testing.T) {
wd, err := os.Getwd()
require.NoError(t, err)

cases := []struct {
input string
expected string
}{
{`c:\foo\bar\baz`, "file:///c:/foo/bar/baz"},
{"/foo/bar/baz", "file:///foo/bar/baz"},
{"foo/bar", "file://" + filepath.Join(wd, "foo/bar")},
}

for _, tt := range cases {
Expand Down
28 changes: 28 additions & 0 deletions generator/cli/kallax/cmd/migrate_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// +build windows

package cmd

import (
"os"
"path/filepath"
"testing"

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

func TestPathToFileURL(t *testing.T) {
wd, err := os.Getwd()
require.NoError(t, err)

cases := []struct {
input string
expected string
}{
{"c:\\foo\\bar\\baz", "file://c:/foo/bar/baz"},
{"foo\\bar", "file://" + filepath.ToSlash(filepath.Join(wd, "foo", "bar"))},
}

for _, tt := range cases {
require.Equal(t, tt.expected, pathToFileURL(tt.input), tt.input)
}
}

0 comments on commit db3e1bc

Please sign in to comment.