зеркало из https://github.com/golang/dep.git
naming changes, make sure relative paths are tested, and a little more error handling
This commit is contained in:
Родитель
a634603f5e
Коммит
95b114ff2c
|
@ -225,7 +225,10 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
|
|||
// vendor does not exist we should write vendor
|
||||
var writeV bool
|
||||
path := filepath.Join(sw.Root, "vendor")
|
||||
vendorIsDir, _ := dep.IsDir(path)
|
||||
vendorIsDir, err := dep.IsDir(path)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ensure vendor is a directory")
|
||||
}
|
||||
vendorEmpty, _ := dep.IsEmptyDir(path)
|
||||
vendorExists := vendorIsDir && !vendorEmpty
|
||||
if !vendorExists && solution != nil {
|
||||
|
|
22
fs_test.go
22
fs_test.go
|
@ -192,32 +192,32 @@ func TestIsEmpty(t *testing.T) {
|
|||
h := test.NewHelper(t)
|
||||
h.TempDir("empty")
|
||||
tests := map[string]string{
|
||||
wd: "false",
|
||||
filepath.Join(wd, "_testdata"): "false",
|
||||
wd: "false",
|
||||
"_testdata": "false",
|
||||
filepath.Join(wd, "main.go"): "err",
|
||||
filepath.Join(wd, "this_file_does_not_exist.thing"): "err",
|
||||
h.Path("empty"): "true",
|
||||
}
|
||||
|
||||
for f, expected := range tests {
|
||||
for f, want := range tests {
|
||||
empty, err := IsEmptyDir(f)
|
||||
if expected == "err" {
|
||||
if want == "err" {
|
||||
if err == nil {
|
||||
t.Fatalf("Expected an error for %v, but it was nil", f)
|
||||
t.Fatalf("Wanted an error for %v, but it was nil", f)
|
||||
}
|
||||
if empty {
|
||||
t.Fatalf("Expected false with error for %v, but got true", f)
|
||||
t.Fatalf("Wanted false with error for %v, but got true", f)
|
||||
}
|
||||
} else if err != nil {
|
||||
t.Fatalf("expected no error for %v, got %v", f, err)
|
||||
t.Fatalf("Wanted no error for %v, got %v", f, err)
|
||||
}
|
||||
|
||||
if expected == "true" && !empty {
|
||||
t.Fatalf("Expected true for %v, but got false", f)
|
||||
if want == "true" && !empty {
|
||||
t.Fatalf("Wanted true for %v, but got false", f)
|
||||
}
|
||||
|
||||
if expected == "false" && empty {
|
||||
t.Fatalf("Expected false for %v, but got true", f)
|
||||
if want == "false" && empty {
|
||||
t.Fatalf("Wanted false for %v, but got true", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче