This file is indexed.

/usr/share/gocode/src/github.com/smartystreets/goconvey/web/server/watcher/gopath_test.go is in golang-github-smartystreets-goconvey-dev 1.5.0-1.

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
65
66
67
68
69
70
71
72
package watcher

import (
	"testing"

	. "github.com/smartystreets/goconvey/convey"
	"github.com/smartystreets/goconvey/web/server/system"
)

func TestGoPath(t *testing.T) {
	var fixture *goPathFixture

	Convey("Subject: goPath abstracts the $GOPATH environment variable", t, func() {
		fixture = newGoPathFixture()

		Convey("Package names should be resolved from paths in consultation with the $GOPATH", func() {
			for packagePath, expected := range resolutions {
				So(fixture.gopath.ResolvePackageName(packagePath), ShouldEqual, expected)
			}
		})

		Convey("Panic should ensue if package name resolution is attempted outside any available workspace", func() {
			defer func() {
				recovered := recover()
				if recovered == nil {
					So(recovered, ShouldNotBeNil)
				} else {
					So(recovered, ShouldStartWith, resolutionError)
				}
			}()
			fixture.gopath.ResolvePackageName("/blah/src/package")
		})
	})
}

type goPathFixture struct {
	shell  *system.FakeShell
	gopath *goPath
}

func newGoPathFixture() *goPathFixture {
	self := &goPathFixture{}

	self.shell = system.NewFakeShell()
	self.shell.Setenv("GOPATH", all)
	self.gopath = newGoPath(self.shell)
	return self
}

const ( // workspaces
	basic    = "/root/gopath"
	newBasic = "/root/otherGopath"
	nested   = "/root/src/gopath"
	crazy    = "/src/github.com"

	all = basic + delimiter + newBasic + delimiter + nested + delimiter + crazy
)

var resolutions = map[string]string{
	"/root/gopath/src/package":                          "package",
	"/root/gopath/src/github.com/package":               "github.com/package",
	"/root/gopath/src/github.com/project/package1":      "github.com/project/package1",
	"/root/otherGopath/src/github.com/project/package2": "github.com/project/package2",
	"/root/src/gopath/src/github.com/project/package3":  "github.com/project/package3",

	// This crazy test case illustrates the point that "/src/" whether indexed at the beginning of the
	// string or the end of the string may not always be the correct way to resolve the package name.
	// In this case, the workspace contains a "src", there is a "src" that connects the workspace to
	// the package (as expected), and there is a "src" in the actual package name.
	// Dear reader, please, don't ever, ever structure your go code like this!
	"/src/github.com/src/github.com/project/src/package": "github.com/project/src/package",
}