Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

dep init - support relative path #571

Merged
merged 3 commits into from
May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
root = ctx.WorkingDir
} else {
root = args[0]
if !filepath.IsAbs(args[0]) {
root = filepath.Join(ctx.WorkingDir, args[0])
}
if err := os.MkdirAll(root, os.FileMode(0777)); err != nil {
Copy link
Collaborator

@ibrasho ibrasho May 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the default 777? Wouldn't 755 be enough for most cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had made it 755 in my previous PR, i got a comment to change it to 777.
#549 (comment)

return errors.Errorf("unable to create directory %s , err %v", root, err)
}
}

mf := filepath.Join(root, dep.ManifestName)
Expand Down
73 changes: 72 additions & 1 deletion cmd/dep/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ func TestIntegration(t *testing.T) {
}
return nil
})

filepath.Walk(filepath.Join("testdata", "init_path_tests"),
func(path string, info os.FileInfo, err error) error {
if err != nil {
t.Fatal("error walking filepath")
}

wd, err := os.Getwd()
if err != nil {
panic(err)
}

if filepath.Base(path) == "testcase.json" {
parse := strings.Split(path, string(filepath.Separator))
testName := strings.Join(parse[2:len(parse)-1], "/")
t.Run(testName, func(t *testing.T) {
t.Parallel()

t.Run("external", testRelativePath(testName, wd, true, execCmd))
t.Run("internal", testRelativePath(testName, wd, false, runMain))
})
}
return nil
})
}

// execCmd is a test.RunFunc which runs the program in another process.
Expand Down Expand Up @@ -85,7 +109,7 @@ func testIntegration(name, wd string, externalProc bool, run test.RunFunc) func(
t.Parallel()

// Set up environment
testCase := test.NewTestCase(t, name, wd)
testCase := test.NewTestCase(t, name, "harness_tests", wd)
defer testCase.Cleanup()
testProj := test.NewTestProject(t, testCase.InitialPath(), wd, externalProc, run)
defer testProj.Cleanup()
Expand Down Expand Up @@ -128,3 +152,50 @@ func testIntegration(name, wd string, externalProc bool, run test.RunFunc) func(
testCase.CompareVendorPaths(testProj.GetVendorPaths())
}
}

func testRelativePath(name, wd string, externalProc bool, run test.RunFunc) func(t *testing.T) {
return func(t *testing.T) {
t.Parallel()

// Set up environment
testCase := test.NewTestCase(t, name, "init_path_tests", wd)
defer testCase.Cleanup()
testProj := test.NewTestProject(t, testCase.InitialPath(), wd, externalProc, run)
defer testProj.Cleanup()

// Create and checkout the vendor revisions
for ip, rev := range testCase.VendorInitial {
testProj.GetVendorGit(ip)
testProj.RunGit(testProj.VendorPath(ip), "checkout", rev)
}

// Create and checkout the import revisions
for ip, rev := range testCase.GopathInitial {
testProj.RunGo("get", ip)
testProj.RunGit(testProj.Path("src", ip), "checkout", rev)
}

// Run commands
testProj.RecordImportPaths()

var err error
for i, args := range testCase.Commands {
err = testProj.DoRun(args)
if err != nil && i < len(testCase.Commands)-1 {
t.Fatalf("cmd %s raised an unexpected error: %s", args[0], err.Error())
}
}

// Check error raised in final command
testCase.CompareError(err, testProj.GetStderr())

// Check output
testCase.CompareOutput(testProj.GetStdout())

// Check final manifest and lock
testCase.CompareFile(dep.ManifestName, testProj.ProjPath(dep.ManifestName))
testCase.CompareFile(dep.LockName, testProj.ProjPath(dep.LockName))

testProj.CompareImportPaths()
}
}
2 changes: 1 addition & 1 deletion cmd/dep/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestRemoveErrors(t *testing.T) {

func removeErrors(name, wd string, externalProc bool, run test.RunFunc) func(*testing.T) {
return func(t *testing.T) {
testCase := test.NewTestCase(t, name, wd)
testCase := test.NewTestCase(t, name, "harness_tests", wd)
testProj := test.NewTestProject(t, testCase.InitialPath(), wd, externalProc, run)
defer testProj.Cleanup()

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

[[dependencies]]
branch = "master"
name = "github.com/sdboyer/deptest"

[[dependencies]]
name = "github.com/sdboyer/deptestdos"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package foo

import "github.com/sdboyer/deptest"

func Foo() deptest.Foo {
var y deptest.Foo

return y
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
"fmt"

"github.com/sdboyer/deptestdos"
)

func main() {
var x deptestdos.Bar
y := foo.FooFunc()

fmt.Println(x, y)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"commands": [
["init", "project_dir"]
],
"init-path": "project_dir"

}
5 changes: 3 additions & 2 deletions internal/test/integration_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ type IntegrationTestCase struct {
GopathInitial map[string]string `json:"gopath-initial"`
VendorInitial map[string]string `json:"vendor-initial"`
VendorFinal []string `json:"vendor-final"`
InitPath string `json:"init-path"`
}

func NewTestCase(t *testing.T, name, wd string) *IntegrationTestCase {
rootPath := filepath.FromSlash(filepath.Join(wd, "testdata", "harness_tests", name))
func NewTestCase(t *testing.T, name, test_dir, wd string) *IntegrationTestCase {
rootPath := filepath.FromSlash(filepath.Join(wd, "testdata", test_dir, name))
n := &IntegrationTestCase{
t: t,
name: name,
Expand Down