Skip to content

Commit bddb1f5

Browse files
bashtiansbuss
authored andcommitted
delay: fix func stable name to strip gopath prefix (#211)
1 parent c71d63e commit bddb1f5

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

delay/delay.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,22 @@ var modVersionPat = regexp.MustCompile("@v[^/]+")
118118
// For calls from package main: strip all leading path entries, leaving just the filename.
119119
// For calls from anywhere else, strip $GOPATH/src, leaving just the package path and file path.
120120
func fileKey(file string) (string, error) {
121-
if !internal.IsSecondGen() || internal.MainPath == "" {
121+
if !internal.IsSecondGen() {
122122
return file, nil
123123
}
124124
// If the caller is in the same Dir as mainPath, then strip everything but the file name.
125125
if filepath.Dir(file) == internal.MainPath {
126126
return filepath.Base(file), nil
127127
}
128-
// If the path contains "_gopath/src/", which is what the builder uses for
128+
// If the path contains "gopath/src/", which is what the builder uses for
129129
// apps which don't use go modules, strip everything up to and including src.
130130
// Or, if the path starts with /tmp/staging, then we're importing a package
131131
// from the app's module (and we must be using go modules), and we have a
132132
// path like /tmp/staging1234/srv/... so strip everything up to and
133133
// including the first /srv/.
134134
// And be sure to look at the GOPATH, for local development.
135135
s := string(filepath.Separator)
136-
for _, s := range []string{filepath.Join("_gopath", "src") + s, s + "srv" + s, filepath.Join(build.Default.GOPATH, "src") + s} {
136+
for _, s := range []string{filepath.Join("gopath", "src") + s, s + "srv" + s, filepath.Join(build.Default.GOPATH, "src") + s} {
137137
if idx := strings.Index(file, s); idx > 0 {
138138
return file[idx+len(s):], nil
139139
}

delay/delay_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func TestStandardContext(t *testing.T) {
466466
}
467467

468468
func TestFileKey(t *testing.T) {
469-
os.Setenv("GAE_ENV", "standard")
469+
const firstGenTest = 0
470470
tests := []struct {
471471
mainPath string
472472
file string
@@ -499,6 +499,16 @@ func TestFileKey(t *testing.T) {
499499
filepath.FromSlash("/tmp/staging3234/srv/_gopath/src/example.com/bar/main.go"),
500500
filepath.FromSlash("example.com/bar/main.go"),
501501
},
502+
{
503+
filepath.FromSlash("/tmp/staging3234/srv/gopath/src/example.com/foo"),
504+
filepath.FromSlash("/tmp/staging3234/srv/gopath/src/example.com/bar/main.go"),
505+
filepath.FromSlash("example.com/bar/main.go"),
506+
},
507+
{
508+
filepath.FromSlash(""),
509+
filepath.FromSlash("/tmp/staging3234/srv/gopath/src/example.com/bar/main.go"),
510+
filepath.FromSlash("example.com/bar/main.go"),
511+
},
502512
// go mod, same package
503513
{
504514
filepath.FromSlash("/tmp/staging3234/srv"),
@@ -520,6 +530,11 @@ func TestFileKey(t *testing.T) {
520530
filepath.FromSlash("/tmp/staging3234/srv/bar/main.go"),
521531
filepath.FromSlash("bar/main.go"),
522532
},
533+
{
534+
filepath.FromSlash(""),
535+
filepath.FromSlash("/tmp/staging3234/srv/bar/main.go"),
536+
filepath.FromSlash("bar/main.go"),
537+
},
523538
// go mod, other package
524539
{
525540
filepath.FromSlash("/tmp/staging3234/srv"),
@@ -528,6 +543,9 @@ func TestFileKey(t *testing.T) {
528543
},
529544
}
530545
for i, tc := range tests {
546+
if i > firstGenTest {
547+
os.Setenv("GAE_ENV", "standard")
548+
}
531549
internal.MainPath = tc.mainPath
532550
got, err := fileKey(tc.file)
533551
if err != nil {

0 commit comments

Comments
 (0)