improve unit testing cases by changing creating testdata path using gdebug.TestdataPath function

This commit is contained in:
John 2020-03-21 23:47:33 +08:00
parent a6a01fd7f2
commit 17aea8d7d4
5 changed files with 16 additions and 16 deletions

View File

@ -29,7 +29,7 @@ import (
func Test_Basic(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
i18n := gi18n.New(gi18n.Options{
Path: gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n",
Path: gdebug.TestDataPath("i18n"),
})
i18n.SetLanguage("none")
t.Assert(i18n.T("{#hello}{#world}"), "{#hello}{#world}")
@ -46,7 +46,7 @@ func Test_Basic(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
i18n := gi18n.New(gi18n.Options{
Path: gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n-file",
Path: gdebug.TestDataPath("i18n-file"),
})
i18n.SetLanguage("none")
t.Assert(i18n.T("{#hello}{#world}"), "{#hello}{#world}")
@ -75,7 +75,7 @@ func Test_Basic(t *testing.T) {
func Test_DefaultManager(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
err := gi18n.SetPath(gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n")
err := gi18n.SetPath(gdebug.TestDataPath("i18n"))
t.Assert(err, nil)
gi18n.SetLanguage("none")

View File

@ -20,8 +20,8 @@ import (
func Test_PackToGoFile(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.CallerDirectory() + "/testdata/files"
goFilePath := gdebug.CallerDirectory() + "/testdata/testdata.go"
srcPath := gdebug.TestDataPath("files")
goFilePath := gdebug.TestDataPath("testdata.go")
pkgName := "testdata"
err := gres.PackToGoFile(srcPath, goFilePath, pkgName)
t.Assert(err, nil)
@ -30,7 +30,7 @@ func Test_PackToGoFile(t *testing.T) {
func Test_Pack(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.CallerDirectory() + "/testdata/files"
srcPath := gdebug.TestDataPath("files")
data, err := gres.Pack(srcPath)
t.Assert(err, nil)
@ -43,7 +43,7 @@ func Test_Pack(t *testing.T) {
func Test_PackToFile(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.CallerDirectory() + "/testdata/files"
srcPath := gdebug.TestDataPath("files")
dstPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
err := gres.PackToFile(srcPath, dstPath)
t.Assert(err, nil)
@ -59,8 +59,8 @@ func Test_PackToFile(t *testing.T) {
func Test_PackMulti(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.CallerDirectory() + "/testdata/files"
goFilePath := gdebug.CallerDirectory() + "/testdata/data/data.go"
srcPath := gdebug.TestDataPath("files")
goFilePath := gdebug.TestDataPath("data/data.go")
pkgName := "data"
array, err := gfile.ScanDir(srcPath, "*", false)
t.Assert(err, nil)
@ -71,8 +71,8 @@ func Test_PackMulti(t *testing.T) {
func Test_PackWithPrefix1(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.CallerDirectory() + "/testdata/files"
goFilePath := gdebug.CallerDirectory() + "/testdata/testdata.go"
srcPath := gdebug.TestDataPath("files")
goFilePath := gdebug.TestDataPath("testdata.go")
pkgName := "testdata"
err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "www/gf-site/test")
t.Assert(err, nil)
@ -81,8 +81,8 @@ func Test_PackWithPrefix1(t *testing.T) {
func Test_PackWithPrefix2(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.CallerDirectory() + "/testdata/files"
goFilePath := gdebug.CallerDirectory() + "/testdata/testdata.go"
srcPath := gdebug.TestDataPath("files")
goFilePath := gdebug.TestDataPath("testdata.go")
pkgName := "testdata"
err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "/var/www/gf-site/test")
t.Assert(err, nil)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -23,7 +23,7 @@ func Test_I18n(t *testing.T) {
expect2 := `john says "こんにちは世界!"`
expect3 := `john says "{#hello}{#world}!"`
g.I18n().SetPath(gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n")
g.I18n().SetPath(gdebug.TestDataPath("i18n"))
g.I18n().SetLanguage("zh-CN")
result1, err := g.View().ParseContent(content, g.Map{