/usr/share/gocode/src/github.com/constabulary/gb/cmd/path_test.go is in golang-github-constabulary-gb-dev 0.4.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 | package cmd
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"testing"
)
var join = filepath.Join
// makeTestData constructs
func makeTestdata(t *testing.T) string {
tempdir, err := filepath.EvalSymlinks(os.TempDir())
if err != nil {
t.Fatal(err)
}
root, err := ioutil.TempDir(tempdir, "path-test")
if err != nil {
t.Fatal(err)
}
mkdir := func(args ...string) string {
path := join(args...)
if err := os.MkdirAll(path, 0777); err != nil {
t.Fatal(err)
}
return path
}
mkfile := func(path string, content string) {
if err := ioutil.WriteFile(path, []byte(content), 0755); err != nil {
t.Fatal(err)
}
}
srcdir := mkdir(root, "src")
mkfile(join(mkdir(srcdir, "a"), "a.go"), "package a")
return root
}
func TestFindProjectroot(t *testing.T) {
root := makeTestdata(t)
defer os.RemoveAll(root)
tests := []struct {
path string
want string
err error
}{
{path: root, want: root},
{path: join(root, "src"), want: root},
{path: join(join(root, "src"), "a"), want: root},
{path: join(root, ".."), err: fmt.Errorf(`could not find project root in "%s" or its parents`, join(root, ".."))},
}
for _, tt := range tests {
got, err := FindProjectroot(tt.path)
if got != tt.want || !reflect.DeepEqual(err, tt.err) {
t.Errorf("FindProjectroot(%v): want: %v, %v, got %v, %v", tt.path, tt.want, tt.err, got, err)
}
}
}
|