From 1f9ead426e3be3f6da6eb43d9a691c8095cb04f3 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Fri, 21 Jun 2019 23:17:27 +0300 Subject: [PATCH] fix travis fail on deprecation example test Former-commit-id: 3f6bb0f01702ab2c2cd7f348b29ec142af036cb3 --- core/router/deprecated.go | 20 ++++++++++++++------ core/router/deprecated_example_test.go | 8 ++++---- core/router/fs.go | 16 ++++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/core/router/deprecated.go b/core/router/deprecated.go index d530f540..a6e7603d 100644 --- a/core/router/deprecated.go +++ b/core/router/deprecated.go @@ -21,13 +21,21 @@ func getCaller() (string, int) { for { frame, more := frames.Next() + file := frame.File - if (!strings.Contains(frame.File, "github.com/kataras/iris") || - strings.Contains(frame.File, "github.com/kataras/iris/_examples") || - strings.Contains(frame.File, "github.com/iris-contrib/examples") || - (strings.Contains(frame.File, "github.com/kataras/iris/core/router") && !strings.Contains(frame.File, "deprecated.go"))) && - !strings.HasSuffix(frame.Func.Name(), ".getCaller") && !strings.Contains(frame.File, "/go/src/testing") { - return frame.File, frame.Line + splitAfterPart := "/src/" + if (!strings.Contains(file, "github.com/kataras/iris") || + strings.Contains(file, "github.com/kataras/iris/_examples") || + strings.Contains(file, "github.com/iris-contrib/examples") || + (strings.Contains(file, "github.com/kataras/iris/core/router") && !strings.Contains(file, "deprecated.go"))) && + !strings.HasSuffix(frame.Func.Name(), ".getCaller") && !strings.Contains(file, "/go/src/testing") { + + // remove the $GOPATH. + n := strings.Index(file, splitAfterPart) + if n != -1 { + file = file[n+len(splitAfterPart):] + } + return file, frame.Line } if !more { diff --git a/core/router/deprecated_example_test.go b/core/router/deprecated_example_test.go index bfab73da..9ff5c553 100644 --- a/core/router/deprecated_example_test.go +++ b/core/router/deprecated_example_test.go @@ -15,7 +15,7 @@ func ExampleParty_StaticWeb() { fmt.Print(err) // Output: StaticWeb is DEPRECATED and it will be removed eventually. - // Source: C:/mygopath/src/github.com/kataras/iris/core/router/deprecated_example_test.go:9 + // Source: github.com/kataras/iris/core/router/deprecated_example_test.go:9 // Use .HandleDir("/static", "./assets") instead. } @@ -30,7 +30,7 @@ func ExampleParty_StaticHandler() { fmt.Print(err) // Output: StaticHandler is DEPRECATED and it will be removed eventually. - // Source: C:/mygopath/src/github.com/kataras/iris/core/router/deprecated_example_test.go:24 + // Source: github.com/kataras/iris/core/router/deprecated_example_test.go:24 // Use iris.FileServer("./assets", iris.DirOptions{ShowList: false, Gzip: true}) instead. } @@ -46,7 +46,7 @@ func ExampleParty_StaticEmbedded() { fmt.Print(err) // Output: StaticEmbedded is DEPRECATED and it will be removed eventually. // It is also miss the AssetInfo bindata function, which is required now. - // Source: C:/mygopath/src/github.com/kataras/iris/core/router/deprecated_example_test.go:39 + // Source: github.com/kataras/iris/core/router/deprecated_example_test.go:39 // Use .HandleDir("/static", "./assets", iris.DirOptions{Asset: Asset, AssetInfo: AssetInfo, AssetNames: AssetNames}) instead. } @@ -62,6 +62,6 @@ func ExampleParty_StaticEmbeddedGzip() { fmt.Print(err) // Output: StaticEmbeddedGzip is DEPRECATED and it will be removed eventually. // It is also miss the AssetInfo bindata function, which is required now. - // Source: C:/mygopath/src/github.com/kataras/iris/core/router/deprecated_example_test.go:55 + // Source: github.com/kataras/iris/core/router/deprecated_example_test.go:55 // Use .HandleDir("/static", "./assets", iris.DirOptions{Gzip: true, Asset: Asset, AssetInfo: AssetInfo, AssetNames: AssetNames}) instead. } diff --git a/core/router/fs.go b/core/router/fs.go index dbe7815a..d2729b46 100644 --- a/core/router/fs.go +++ b/core/router/fs.go @@ -100,9 +100,8 @@ type embeddedFileSystem struct { vdir string dirNames map[string]*embeddedDir // embedded tools doesn't give that info, so we initialize it in order to support `ShowList` on embedded files as well. - asset func(name string) ([]byte, error) - assetInfo func(name string) (os.FileInfo, error) - assetNames []string + asset func(name string) ([]byte, error) + assetInfo func(name string) (os.FileInfo, error) } var _ http.FileSystem = (*embeddedFileSystem)(nil) @@ -263,13 +262,14 @@ func FileServer(directory string, opts ...DirOptions) context.Handler { vdir: vdir, dirNames: dirNames, - asset: asset, - assetInfo: assetInfo, - assetNames: names, + asset: asset, + assetInfo: assetInfo, } - } else if !DirectoryExists(directory) { - panic("FileServer: system directory: " + directory + " does not exist") } + // Let it for now. + // else if !DirectoryExists(directory) { + // panic("FileServer: system directory: " + directory + " does not exist") + // } plainStatusCode := func(ctx context.Context, statusCode int) { if writer, ok := ctx.ResponseWriter().(*context.GzipResponseWriter); ok && writer != nil {