diff --git a/debug/gdebug/gdebug_testdata.go b/debug/gdebug/gdebug_testdata.go index 2d258d5d2..d16705f39 100644 --- a/debug/gdebug/gdebug_testdata.go +++ b/debug/gdebug/gdebug_testdata.go @@ -10,10 +10,10 @@ import ( "path/filepath" ) -// TestDataPath retrieves and returns the testdata path of current package. -// It is used for unit testing cases only. -// The parameter specifies the underlying sub-folders/sub-files, -// which will be joined with current system separator. +// TestDataPath retrieves and returns the testdata path of current package, +// which is used for unit testing cases only. +// The parameter specifies the its sub-folders/sub-files, +// which will be joined with current system separator and returned with the path. func TestDataPath(names ...string) string { path := CallerDirectory() + string(filepath.Separator) + "testdata" for _, name := range names { diff --git a/encoding/gbase64/gbase64_test.go b/encoding/gbase64/gbase64_test.go index 70e1d89bd..8286b648e 100644 --- a/encoding/gbase64/gbase64_test.go +++ b/encoding/gbase64/gbase64_test.go @@ -67,7 +67,7 @@ func Test_Basic(t *testing.T) { } func Test_File(t *testing.T) { - path := gfile.Join(gdebug.TestDataPath(), "test") + path := gdebug.TestDataPath("test") expect := "dGVzdA==" gtest.C(t, func(t *gtest.T) { b, err := gbase64.EncodeFile(path) diff --git a/encoding/gcompress/gcompress_z_unit_gzip_test.go b/encoding/gcompress/gcompress_z_unit_gzip_test.go index 2acf033a3..2e43558fa 100644 --- a/encoding/gcompress/gcompress_z_unit_gzip_test.go +++ b/encoding/gcompress/gcompress_z_unit_gzip_test.go @@ -43,7 +43,7 @@ func Test_Gzip_UnGzip(t *testing.T) { } func Test_Gzip_UnGzip_File(t *testing.T) { - srcPath := gfile.Join(gdebug.TestDataPath(), "gzip", "file.txt") + srcPath := gdebug.TestDataPath("gzip", "file.txt") dstPath1 := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr(), "gzip.zip") dstPath2 := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr(), "file.txt") diff --git a/encoding/gcompress/gcompress_z_unit_zip_test.go b/encoding/gcompress/gcompress_z_unit_zip_test.go index 5aa447260..757675b20 100644 --- a/encoding/gcompress/gcompress_z_unit_zip_test.go +++ b/encoding/gcompress/gcompress_z_unit_zip_test.go @@ -20,8 +20,8 @@ import ( func Test_ZipPath(t *testing.T) { // file gtest.C(t, func(t *gtest.T) { - srcPath := gfile.Join(gdebug.TestDataPath(), "zip", "path1", "1.txt") - dstPath := gfile.Join(gdebug.TestDataPath(), "zip", "zip.zip") + srcPath := gdebug.TestDataPath("zip", "path1", "1.txt") + dstPath := gdebug.TestDataPath("zip", "zip.zip") t.Assert(gfile.Exists(dstPath), false) err := gcompress.ZipPath(srcPath, dstPath) @@ -44,8 +44,8 @@ func Test_ZipPath(t *testing.T) { }) // directory gtest.C(t, func(t *gtest.T) { - srcPath := gfile.Join(gdebug.TestDataPath(), "zip") - dstPath := gfile.Join(gdebug.TestDataPath(), "zip", "zip.zip") + srcPath := gdebug.TestDataPath("zip") + dstPath := gdebug.TestDataPath("zip", "zip.zip") pwd := gfile.Pwd() err := gfile.Chdir(srcPath) @@ -77,10 +77,10 @@ func Test_ZipPath(t *testing.T) { }) // multiple paths joined using char ',' gtest.C(t, func(t *gtest.T) { - srcPath := gfile.Join(gdebug.TestDataPath(), "zip") - srcPath1 := gfile.Join(gdebug.TestDataPath(), "zip", "path1") - srcPath2 := gfile.Join(gdebug.TestDataPath(), "zip", "path2") - dstPath := gfile.Join(gdebug.TestDataPath(), "zip", "zip.zip") + srcPath := gdebug.TestDataPath("zip") + srcPath1 := gdebug.TestDataPath("zip", "path1") + srcPath2 := gdebug.TestDataPath("zip", "path2") + dstPath := gdebug.TestDataPath("zip", "zip.zip") pwd := gfile.Pwd() err := gfile.Chdir(srcPath) @@ -116,9 +116,9 @@ func Test_ZipPath(t *testing.T) { func Test_ZipPathWriter(t *testing.T) { gtest.C(t, func(t *gtest.T) { - srcPath := gfile.Join(gdebug.TestDataPath(), "zip") - srcPath1 := gfile.Join(gdebug.TestDataPath(), "zip", "path1") - srcPath2 := gfile.Join(gdebug.TestDataPath(), "zip", "path2") + srcPath := gdebug.TestDataPath("zip") + srcPath1 := gdebug.TestDataPath("zip", "path1") + srcPath2 := gdebug.TestDataPath("zip", "path2") pwd := gfile.Pwd() err := gfile.Chdir(srcPath) diff --git a/encoding/gjson/gjson_z_example_load_test.go b/encoding/gjson/gjson_z_example_load_test.go index d2acebb96..d8ea84a8d 100644 --- a/encoding/gjson/gjson_z_example_load_test.go +++ b/encoding/gjson/gjson_z_example_load_test.go @@ -14,14 +14,14 @@ import ( ) func Example_LoadJson() { - jsonFilePath := gfile.Join(gdebug.TestDataPath(), "json", "data1.json") + jsonFilePath := gdebug.TestDataPath("json", "data1.json") j, _ := gjson.Load(jsonFilePath) fmt.Println(j.Get("name")) fmt.Println(j.Get("score")) } func Example_LoadXml() { - jsonFilePath := gfile.Join(gdebug.TestDataPath(), "xml", "data1.xml") + jsonFilePath := gdebug.TestDataPath("xml", "data1.xml") j, _ := gjson.Load(jsonFilePath) fmt.Println(j.Get("doc.name")) fmt.Println(j.Get("doc.score")) diff --git a/frame/gins/gins_z_unit_config_test.go b/frame/gins/gins_z_unit_config_test.go index 0ba1cc54d..4e1bc4a6e 100644 --- a/frame/gins/gins_z_unit_config_test.go +++ b/frame/gins/gins_z_unit_config_test.go @@ -22,7 +22,7 @@ import ( var ( configContent = gfile.GetContents( - gfile.Join(gdebug.TestDataPath(), "config", "config.toml"), + gdebug.TestDataPath("config", "config.toml"), ) ) diff --git a/frame/gins/gins_z_unit_database_test.go b/frame/gins/gins_z_unit_database_test.go index b3a82a955..44ea6c22c 100644 --- a/frame/gins/gins_z_unit_database_test.go +++ b/frame/gins/gins_z_unit_database_test.go @@ -19,7 +19,7 @@ import ( func Test_Database(t *testing.T) { databaseContent := gfile.GetContents( - gfile.Join(gdebug.TestDataPath(), "database", "config.toml"), + gdebug.TestDataPath("database", "config.toml"), ) gtest.C(t, func(t *gtest.T) { var err error diff --git a/frame/gins/gins_z_unit_redis_test.go b/frame/gins/gins_z_unit_redis_test.go index a9fdc679e..0a7e6a86d 100644 --- a/frame/gins/gins_z_unit_redis_test.go +++ b/frame/gins/gins_z_unit_redis_test.go @@ -19,7 +19,7 @@ import ( func Test_Redis(t *testing.T) { redisContent := gfile.GetContents( - gfile.Join(gdebug.TestDataPath(), "redis", "config.toml"), + gdebug.TestDataPath("redis", "config.toml"), ) gtest.C(t, func(t *gtest.T) { diff --git a/frame/gins/gins_z_unit_view_test.go b/frame/gins/gins_z_unit_view_test.go index c8f0cf34b..e03f398dd 100644 --- a/frame/gins/gins_z_unit_view_test.go +++ b/frame/gins/gins_z_unit_view_test.go @@ -52,7 +52,7 @@ func Test_View(t *testing.T) { func Test_View_Config(t *testing.T) { // view1 test1 gtest.C(t, func(t *gtest.T) { - dirPath := gfile.Join(gdebug.TestDataPath(), "view1") + dirPath := gdebug.TestDataPath("view1") gcfg.SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml"))) defer gcfg.ClearContent() defer instances.Clear() @@ -74,7 +74,7 @@ func Test_View_Config(t *testing.T) { }) // view1 test2 gtest.C(t, func(t *gtest.T) { - dirPath := gfile.Join(gdebug.TestDataPath(), "view1") + dirPath := gdebug.TestDataPath("view1") gcfg.SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml"))) defer gcfg.ClearContent() defer instances.Clear() @@ -96,7 +96,7 @@ func Test_View_Config(t *testing.T) { }) // view2 gtest.C(t, func(t *gtest.T) { - dirPath := gfile.Join(gdebug.TestDataPath(), "view2") + dirPath := gdebug.TestDataPath("view2") gcfg.SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml"))) defer gcfg.ClearContent() defer instances.Clear() @@ -118,7 +118,7 @@ func Test_View_Config(t *testing.T) { }) // view2 gtest.C(t, func(t *gtest.T) { - dirPath := gfile.Join(gdebug.TestDataPath(), "view2") + dirPath := gdebug.TestDataPath("view2") gcfg.SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml"))) defer gcfg.ClearContent() defer instances.Clear() diff --git a/net/ghttp/ghttp_unit_middleware_basic_test.go b/net/ghttp/ghttp_unit_middleware_basic_test.go index 62f188b2f..7ce9420f2 100644 --- a/net/ghttp/ghttp_unit_middleware_basic_test.go +++ b/net/ghttp/ghttp_unit_middleware_basic_test.go @@ -178,7 +178,7 @@ func Test_Middleware_With_Static(t *testing.T) { }) s.SetPort(p) s.SetDumpRouterMap(false) - s.SetServerRoot(gfile.Join(gdebug.TestDataPath(), "static1")) + s.SetServerRoot(gdebug.TestDataPath("static1")) s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) @@ -250,7 +250,7 @@ func Test_Middleware_Hook_With_Static(t *testing.T) { }) s.SetPort(p) //s.SetDumpRouterMap(false) - s.SetServerRoot(gfile.Join(gdebug.TestDataPath(), "static1")) + s.SetServerRoot(gdebug.TestDataPath("static1")) s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) diff --git a/net/ghttp/ghttp_unit_param_file_test.go b/net/ghttp/ghttp_unit_param_file_test.go index b21b5beb2..1d5b9ac2c 100644 --- a/net/ghttp/ghttp_unit_param_file_test.go +++ b/net/ghttp/ghttp_unit_param_file_test.go @@ -45,7 +45,7 @@ func Test_Params_File_Single(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - srcPath := gfile.Join(gdebug.TestDataPath(), "upload", "file1.txt") + srcPath := gdebug.TestDataPath("upload", "file1.txt") dstPath := gfile.Join(dstDirPath, "file1.txt") content := client.PostContent("/upload/single", g.Map{ "file": "@file:" + srcPath, @@ -61,7 +61,7 @@ func Test_Params_File_Single(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - srcPath := gfile.Join(gdebug.TestDataPath(), "upload", "file2.txt") + srcPath := gdebug.TestDataPath("upload", "file2.txt") content := client.PostContent("/upload/single", g.Map{ "file": "@file:" + srcPath, "randomlyRename": true, @@ -98,7 +98,7 @@ func Test_Params_File_CustomName(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - srcPath := gfile.Join(gdebug.TestDataPath(), "upload", "file1.txt") + srcPath := gdebug.TestDataPath("upload", "file1.txt") dstPath := gfile.Join(dstDirPath, "my.txt") content := client.PostContent("/upload/single", g.Map{ "file": "@file:" + srcPath, @@ -135,8 +135,8 @@ func Test_Params_File_Batch(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - srcPath1 := gfile.Join(gdebug.TestDataPath(), "upload", "file1.txt") - srcPath2 := gfile.Join(gdebug.TestDataPath(), "upload", "file2.txt") + srcPath1 := gdebug.TestDataPath("upload", "file1.txt") + srcPath2 := gdebug.TestDataPath("upload", "file2.txt") dstPath1 := gfile.Join(dstDirPath, "file1.txt") dstPath2 := gfile.Join(dstDirPath, "file2.txt") content := client.PostContent("/upload/batch", g.Map{ @@ -155,8 +155,8 @@ func Test_Params_File_Batch(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - srcPath1 := gfile.Join(gdebug.TestDataPath(), "upload", "file1.txt") - srcPath2 := gfile.Join(gdebug.TestDataPath(), "upload", "file2.txt") + srcPath1 := gdebug.TestDataPath("upload", "file1.txt") + srcPath2 := gdebug.TestDataPath("upload", "file2.txt") content := client.PostContent("/upload/batch", g.Map{ "file[0]": "@file:" + srcPath1, "file[1]": "@file:" + srcPath2, diff --git a/net/ghttp/ghttp_unit_static_test.go b/net/ghttp/ghttp_unit_static_test.go index 8cafbf169..f9ae39e87 100644 --- a/net/ghttp/ghttp_unit_static_test.go +++ b/net/ghttp/ghttp_unit_static_test.go @@ -66,7 +66,7 @@ func Test_Static_ServerRoot_Security(t *testing.T) { gtest.C(t, func(t *gtest.T) { p := ports.PopRand() s := g.Server(p) - s.SetServerRoot(gfile.Join(gdebug.TestDataPath(), "static1")) + s.SetServerRoot(gdebug.TestDataPath("static1")) s.SetPort(p) s.Start() defer s.Shutdown() diff --git a/net/ghttp/ghttp_unit_template_test.go b/net/ghttp/ghttp_unit_template_test.go index d21dff079..75c6395f0 100644 --- a/net/ghttp/ghttp_unit_template_test.go +++ b/net/ghttp/ghttp_unit_template_test.go @@ -24,7 +24,7 @@ import ( func Test_Template_Basic(t *testing.T) { gtest.C(t, func(t *gtest.T) { - v := gview.New(gfile.Join(gdebug.TestDataPath(), "template", "basic")) + v := gview.New(gdebug.TestDataPath("template", "basic")) p := ports.PopRand() s := g.Server(p) s.SetView(v) @@ -49,7 +49,7 @@ func Test_Template_Basic(t *testing.T) { func Test_Template_Encode(t *testing.T) { gtest.C(t, func(t *gtest.T) { - v := gview.New(gfile.Join(gdebug.TestDataPath(), "template", "basic")) + v := gview.New(gdebug.TestDataPath("template", "basic")) v.SetAutoEncode(true) p := ports.PopRand() s := g.Server(p) @@ -75,7 +75,7 @@ func Test_Template_Encode(t *testing.T) { func Test_Template_Layout1(t *testing.T) { gtest.C(t, func(t *gtest.T) { - v := gview.New(gfile.Join(gdebug.TestDataPath(), "template", "layout1")) + v := gview.New(gdebug.TestDataPath("template", "layout1")) p := ports.PopRand() s := g.Server(p) s.SetView(v) @@ -105,7 +105,7 @@ func Test_Template_Layout1(t *testing.T) { func Test_Template_Layout2(t *testing.T) { gtest.C(t, func(t *gtest.T) { - v := gview.New(gfile.Join(gdebug.TestDataPath(), "template", "layout2")) + v := gview.New(gdebug.TestDataPath("template", "layout2")) p := ports.PopRand() s := g.Server(p) s.SetView(v) diff --git a/os/gview/gview_unit_config_test.go b/os/gview/gview_unit_config_test.go index cb2e764c1..e901f69bf 100644 --- a/os/gview/gview_unit_config_test.go +++ b/os/gview/gview_unit_config_test.go @@ -18,7 +18,7 @@ import ( func Test_Config(t *testing.T) { gtest.C(t, func(t *gtest.T) { config := gview.Config{ - Paths: []string{gfile.Join(gdebug.TestDataPath(), "config")}, + Paths: []string{gdebug.TestDataPath("config")}, Data: g.Map{ "name": "gf", }, @@ -45,7 +45,7 @@ func Test_ConfigWithMap(t *testing.T) { gtest.C(t, func(t *gtest.T) { view := gview.New() err := view.SetConfigWithMap(g.Map{ - "Paths": []string{gfile.Join(gdebug.TestDataPath(), "config")}, + "Paths": []string{gdebug.TestDataPath("config")}, "DefaultFile": "test.html", "Delimiters": []string{"${", "}"}, "Data": g.Map{