Skip to content

Commit

Permalink
fix: init cmd path error on windows. (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
narrowizard authored and caicloud-bot committed Mar 12, 2019
1 parent b67c3ce commit e559644
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion utils/project/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func PackageForPath(directory string) (string, error) {
if err != nil {
return "", err
}
return strings.Trim(absPath[len(srcPath(goPath)):], "/"), nil
return filepath.ToSlash(strings.Trim(absPath[len(srcPath(goPath)):], string(os.PathSeparator))), nil
}

// Subdirectories walkthroughs all subdirectories. The results contains itself.
Expand Down
33 changes: 33 additions & 0 deletions utils/project/path_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2018 Caicloud Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package project

import (
"testing"
)

func TestPackageForPath(t *testing.T) {
directory := "./test1"
dest := "github.com/caicloud/nirvana/utils/project/test1"
packagePath, err := PackageForPath(directory)
if err != nil {
t.Error(err)
}
if packagePath != dest {
t.Error(packagePath)
}
}

0 comments on commit e559644

Please sign in to comment.