forked from golang/dep
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
51 lines (43 loc) · 1.44 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 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 (
"os"
"path/filepath"
"runtime"
"testing"
)
func TestFindRoot(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
expect := filepath.Join(wd, "_testdata", "rootfind")
got1, err := findProjectRoot(expect)
if err != nil {
t.Errorf("Unexpected error while finding root: %s", err)
} else if expect != got1 {
t.Errorf("findProjectRoot directly on root dir should have found %s, got %s", expect, got1)
}
got2, err := findProjectRoot(filepath.Join(expect, "subdir"))
if err != nil {
t.Errorf("Unexpected error while finding root: %s", err)
} else if expect != got2 {
t.Errorf("findProjectRoot on subdir should have found %s, got %s", expect, got2)
}
got3, err := findProjectRoot(filepath.Join(expect, "nonexistent"))
if err != nil {
t.Errorf("Unexpected error while finding root: %s", err)
} else if expect != got3 {
t.Errorf("findProjectRoot on nonexistent subdir should still work and give %s, got %s", expect, got3)
}
// the following test does not work on windows because syscall.Stat does not
// return a "not a directory" error
if runtime.GOOS != "windows" {
got4, err := findProjectRoot(filepath.Join(expect, manifestName))
if err == nil {
t.Errorf("Should have err'd when trying subdir of file, but returned %s", got4)
}
}
}