Skip to content

Commit bceb5fc

Browse files
committed
rename gdebug.TestData* -> gtest.Data*; add UT case for http server
1 parent b3e66d8 commit bceb5fc

34 files changed

+167
-152
lines changed

database/gdb/gdb_z_mysql_feature_model_struct_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ func Test_Scan_JsonAttributes(t *testing.T) {
550550
}
551551

552552
table := "jfy_gift"
553-
array := gstr.SplitAndTrim(gtest.TestDataContent(`issue1380.sql`), ";")
553+
array := gstr.SplitAndTrim(gtest.DataContent(`issue1380.sql`), ";")
554554
for _, v := range array {
555555
if _, err := db.Exec(ctx, v); err != nil {
556556
gtest.Error(err)

database/gdb/gdb_z_mysql_feature_with_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"fmt"
1111
"testing"
1212

13-
"github.com/gogf/gf/v2/debug/gdebug"
1413
"github.com/gogf/gf/v2/frame/g"
1514
"github.com/gogf/gf/v2/os/gfile"
1615
"github.com/gogf/gf/v2/test/gtest"
@@ -1644,7 +1643,7 @@ func Test_Table_Relation_With_MultipleDepends1(t *testing.T) {
16441643
dropTable("table_b")
16451644
dropTable("table_c")
16461645
}()
1647-
for _, v := range gstr.SplitAndTrim(gfile.GetContents(gdebug.TestDataPath("with_multiple_depends.sql")), ";") {
1646+
for _, v := range gstr.SplitAndTrim(gfile.GetContents(gtest.DataPath("with_multiple_depends.sql")), ";") {
16481647
if _, err := db.Exec(ctx, v); err != nil {
16491648
gtest.Error(err)
16501649
}
@@ -1716,7 +1715,7 @@ func Test_Table_Relation_With_MultipleDepends2(t *testing.T) {
17161715
dropTable("table_b")
17171716
dropTable("table_c")
17181717
}()
1719-
for _, v := range gstr.SplitAndTrim(gfile.GetContents(gdebug.TestDataPath("with_multiple_depends.sql")), ";") {
1718+
for _, v := range gstr.SplitAndTrim(gfile.GetContents(gtest.DataPath("with_multiple_depends.sql")), ";") {
17201719
if _, err := db.Exec(ctx, v); err != nil {
17211720
gtest.Error(err)
17221721
}
@@ -1803,7 +1802,7 @@ func Test_Table_Relation_With_MultipleDepends_Embedded(t *testing.T) {
18031802
dropTable("table_b")
18041803
dropTable("table_c")
18051804
}()
1806-
for _, v := range gstr.SplitAndTrim(gfile.GetContents(gdebug.TestDataPath("with_multiple_depends.sql")), ";") {
1805+
for _, v := range gstr.SplitAndTrim(gfile.GetContents(gtest.DataPath("with_multiple_depends.sql")), ";") {
18071806
if _, err := db.Exec(ctx, v); err != nil {
18081807
gtest.Error(err)
18091808
}
@@ -1996,7 +1995,7 @@ func Test_With_Feature_Issue1401(t *testing.T) {
19961995
table1 = "parcels"
19971996
table2 = "parcel_items"
19981997
)
1999-
array := gstr.SplitAndTrim(gtest.TestDataContent(`issue1401.sql`), ";")
1998+
array := gstr.SplitAndTrim(gtest.DataContent(`issue1401.sql`), ";")
20001999
for _, v := range array {
20012000
if _, err := db.Exec(ctx, v); err != nil {
20022001
gtest.Error(err)
@@ -2038,7 +2037,7 @@ func Test_With_Feature_Issue1412(t *testing.T) {
20382037
table1 = "parcels"
20392038
table2 = "items"
20402039
)
2041-
array := gstr.SplitAndTrim(gtest.TestDataContent(`issue1412.sql`), ";")
2040+
array := gstr.SplitAndTrim(gtest.DataContent(`issue1412.sql`), ";")
20422041
for _, v := range array {
20432042
if _, err := db.Exec(ctx, v); err != nil {
20442043
gtest.Error(err)

database/gdb/gdb_z_mysql_model_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/gogf/gf/v2/container/garray"
1919
"github.com/gogf/gf/v2/container/gmap"
2020
"github.com/gogf/gf/v2/database/gdb"
21-
"github.com/gogf/gf/v2/debug/gdebug"
2221
"github.com/gogf/gf/v2/encoding/gjson"
2322
"github.com/gogf/gf/v2/frame/g"
2423
"github.com/gogf/gf/v2/os/gfile"
@@ -2195,7 +2194,7 @@ func Test_Model_FieldsEx_WithReservedWords(t *testing.T) {
21952194
gtest.C(t, func(t *gtest.T) {
21962195
var (
21972196
table = "fieldsex_test_table"
2198-
sqlTpcPath = gdebug.TestDataPath("reservedwords_table_tpl.sql")
2197+
sqlTpcPath = gtest.DataPath("reservedwords_table_tpl.sql")
21992198
sqlContent = gfile.GetContents(sqlTpcPath)
22002199
)
22012200
t.AssertNE(sqlContent, "")

debug/gdebug/gdebug_testdata.go

-36
This file was deleted.

encoding/gbase64/gbase64_z_unit_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package gbase64_test
99
import (
1010
"testing"
1111

12-
"github.com/gogf/gf/v2/debug/gdebug"
1312
"github.com/gogf/gf/v2/encoding/gbase64"
1413
"github.com/gogf/gf/v2/test/gtest"
1514
)
@@ -66,7 +65,7 @@ func Test_Basic(t *testing.T) {
6665
}
6766

6867
func Test_File(t *testing.T) {
69-
path := gdebug.TestDataPath("test")
68+
path := gtest.DataPath("test")
7069
expect := "dGVzdA=="
7170
gtest.C(t, func(t *gtest.T) {
7271
b, err := gbase64.EncodeFile(path)

encoding/gcompress/gcompress_z_unit_gzip_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package gcompress_test
99
import (
1010
"testing"
1111

12-
"github.com/gogf/gf/v2/debug/gdebug"
1312
"github.com/gogf/gf/v2/encoding/gcompress"
1413
"github.com/gogf/gf/v2/os/gfile"
1514
"github.com/gogf/gf/v2/os/gtime"
@@ -43,7 +42,7 @@ func Test_Gzip_UnGzip(t *testing.T) {
4342
}
4443

4544
func Test_Gzip_UnGzip_File(t *testing.T) {
46-
srcPath := gdebug.TestDataPath("gzip", "file.txt")
45+
srcPath := gtest.DataPath("gzip", "file.txt")
4746
dstPath1 := gfile.Temp(gtime.TimestampNanoStr(), "gzip.zip")
4847
dstPath2 := gfile.Temp(gtime.TimestampNanoStr(), "file.txt")
4948

encoding/gcompress/gcompress_z_unit_zip_test.go

+15-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"bytes"
1111
"testing"
1212

13-
"github.com/gogf/gf/v2/debug/gdebug"
1413
"github.com/gogf/gf/v2/encoding/gcompress"
1514
"github.com/gogf/gf/v2/os/gfile"
1615
"github.com/gogf/gf/v2/os/gtime"
@@ -20,8 +19,8 @@ import (
2019
func Test_ZipPath(t *testing.T) {
2120
// file
2221
gtest.C(t, func(t *gtest.T) {
23-
srcPath := gdebug.TestDataPath("zip", "path1", "1.txt")
24-
dstPath := gdebug.TestDataPath("zip", "zip.zip")
22+
srcPath := gtest.DataPath("zip", "path1", "1.txt")
23+
dstPath := gtest.DataPath("zip", "zip.zip")
2524

2625
t.Assert(gfile.Exists(dstPath), false)
2726
t.Assert(gcompress.ZipPath(srcPath, dstPath), nil)
@@ -42,8 +41,8 @@ func Test_ZipPath(t *testing.T) {
4241
// multiple files
4342
gtest.C(t, func(t *gtest.T) {
4443
var (
45-
srcPath1 = gdebug.TestDataPath("zip", "path1", "1.txt")
46-
srcPath2 = gdebug.TestDataPath("zip", "path2", "2.txt")
44+
srcPath1 = gtest.DataPath("zip", "path1", "1.txt")
45+
srcPath2 = gtest.DataPath("zip", "path2", "2.txt")
4746
dstPath = gfile.Temp(gtime.TimestampNanoStr(), "zip.zip")
4847
)
4948
if p := gfile.Dir(dstPath); !gfile.Exists(p) {
@@ -75,8 +74,8 @@ func Test_ZipPath(t *testing.T) {
7574
// one dir and one file.
7675
gtest.C(t, func(t *gtest.T) {
7776
var (
78-
srcPath1 = gdebug.TestDataPath("zip", "path1")
79-
srcPath2 = gdebug.TestDataPath("zip", "path2", "2.txt")
77+
srcPath1 = gtest.DataPath("zip", "path1")
78+
srcPath2 = gtest.DataPath("zip", "path2", "2.txt")
8079
dstPath = gfile.Temp(gtime.TimestampNanoStr(), "zip.zip")
8180
)
8281
if p := gfile.Dir(dstPath); !gfile.Exists(p) {
@@ -107,8 +106,8 @@ func Test_ZipPath(t *testing.T) {
107106
})
108107
// directory.
109108
gtest.C(t, func(t *gtest.T) {
110-
srcPath := gdebug.TestDataPath("zip")
111-
dstPath := gdebug.TestDataPath("zip", "zip.zip")
109+
srcPath := gtest.DataPath("zip")
110+
dstPath := gtest.DataPath("zip", "zip.zip")
112111

113112
pwd := gfile.Pwd()
114113
err := gfile.Chdir(srcPath)
@@ -141,10 +140,10 @@ func Test_ZipPath(t *testing.T) {
141140
// multiple directory paths joined using char ','.
142141
gtest.C(t, func(t *gtest.T) {
143142
var (
144-
srcPath = gdebug.TestDataPath("zip")
145-
srcPath1 = gdebug.TestDataPath("zip", "path1")
146-
srcPath2 = gdebug.TestDataPath("zip", "path2")
147-
dstPath = gdebug.TestDataPath("zip", "zip.zip")
143+
srcPath = gtest.DataPath("zip")
144+
srcPath1 = gtest.DataPath("zip", "path1")
145+
srcPath2 = gtest.DataPath("zip", "path2")
146+
dstPath = gtest.DataPath("zip", "zip.zip")
148147
)
149148
pwd := gfile.Pwd()
150149
err := gfile.Chdir(srcPath)
@@ -181,9 +180,9 @@ func Test_ZipPath(t *testing.T) {
181180
func Test_ZipPathWriter(t *testing.T) {
182181
gtest.C(t, func(t *gtest.T) {
183182
var (
184-
srcPath = gdebug.TestDataPath("zip")
185-
srcPath1 = gdebug.TestDataPath("zip", "path1")
186-
srcPath2 = gdebug.TestDataPath("zip", "path2")
183+
srcPath = gtest.DataPath("zip")
184+
srcPath1 = gtest.DataPath("zip", "path1")
185+
srcPath2 = gtest.DataPath("zip", "path2")
187186
)
188187
pwd := gfile.Pwd()
189188
err := gfile.Chdir(srcPath)

encoding/gjson/gjson_z_example_load_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ package gjson_test
99
import (
1010
"fmt"
1111

12-
"github.com/gogf/gf/v2/debug/gdebug"
1312
"github.com/gogf/gf/v2/encoding/gjson"
13+
"github.com/gogf/gf/v2/test/gtest"
1414
)
1515

1616
func ExampleLoad() {
17-
jsonFilePath := gdebug.TestDataPath("json", "data1.json")
17+
jsonFilePath := gtest.DataPath("json", "data1.json")
1818
j, _ := gjson.Load(jsonFilePath)
1919
fmt.Println(j.Get("name"))
2020
fmt.Println(j.Get("score"))
2121

22-
notExistFilePath := gdebug.TestDataPath("json", "data2.json")
22+
notExistFilePath := gtest.DataPath("json", "data2.json")
2323
j2, _ := gjson.Load(notExistFilePath)
2424
fmt.Println(j2.Get("name"))
2525

@@ -195,7 +195,7 @@ func ExampleIsValidDataType() {
195195
}
196196

197197
func ExampleLoad_Xml() {
198-
jsonFilePath := gdebug.TestDataPath("xml", "data1.xml")
198+
jsonFilePath := gtest.DataPath("xml", "data1.xml")
199199
j, _ := gjson.Load(jsonFilePath)
200200
fmt.Println(j.Get("doc.name"))
201201
fmt.Println(j.Get("doc.score"))

frame/gins/gins_server.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ func Server(name ...interface{}) *ghttp.Server {
5858
}
5959
}
6060
}
61-
// Server configuration.
61+
// Automatically retrieve configuration by instance name.
6262
serverConfigMap = Config().MustGet(
6363
ctx,
64-
fmt.Sprintf(`%s.%s`, configNodeName, server.GetName()),
64+
fmt.Sprintf(`%s.%s`, configNodeName, instanceName),
6565
).Map()
6666
if len(serverConfigMap) == 0 {
6767
serverConfigMap = Config().MustGet(ctx, configNodeName).Map()
@@ -81,7 +81,7 @@ func Server(name ...interface{}) *ghttp.Server {
8181
// Server logger configuration checks.
8282
serverLoggerConfigMap = Config().MustGet(
8383
ctx,
84-
fmt.Sprintf(`%s.%s.%s`, configNodeName, server.GetName(), configNodeNameLogger),
84+
fmt.Sprintf(`%s.%s.%s`, configNodeName, instanceName, configNodeNameLogger),
8585
).Map()
8686
if len(serverLoggerConfigMap) > 0 {
8787
if err = server.Logger().SetConfigWithMap(serverLoggerConfigMap); err != nil {

frame/gins/gins_z_unit_config_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"testing"
1313
"time"
1414

15-
"github.com/gogf/gf/v2/debug/gdebug"
1615
"github.com/gogf/gf/v2/frame/gins"
1716
"github.com/gogf/gf/v2/os/gcfg"
1817
"github.com/gogf/gf/v2/os/gfile"
@@ -23,7 +22,7 @@ import (
2322
var (
2423
ctx = context.Background()
2524
configContent = gfile.GetContents(
26-
gdebug.TestDataPath("config", "config.toml"),
25+
gtest.DataPath("config", "config.toml"),
2726
)
2827
)
2928

frame/gins/gins_z_unit_database_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"testing"
1111
"time"
1212

13-
"github.com/gogf/gf/v2/debug/gdebug"
1413
"github.com/gogf/gf/v2/frame/gins"
1514
"github.com/gogf/gf/v2/os/gcfg"
1615
"github.com/gogf/gf/v2/os/gfile"
@@ -20,7 +19,7 @@ import (
2019

2120
func Test_Database(t *testing.T) {
2221
databaseContent := gfile.GetContents(
23-
gdebug.TestDataPath("database", "config.toml"),
22+
gtest.DataPath("database", "config.toml"),
2423
)
2524
gtest.C(t, func(t *gtest.T) {
2625
var err error

frame/gins/gins_z_unit_redis_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"testing"
1111
"time"
1212

13-
"github.com/gogf/gf/v2/debug/gdebug"
1413
"github.com/gogf/gf/v2/frame/gins"
1514
"github.com/gogf/gf/v2/os/gcfg"
1615
"github.com/gogf/gf/v2/os/gfile"
@@ -20,7 +19,7 @@ import (
2019

2120
func Test_Redis(t *testing.T) {
2221
redisContent := gfile.GetContents(
23-
gdebug.TestDataPath("redis", "config.toml"),
22+
gtest.DataPath("redis", "config.toml"),
2423
)
2524

2625
gtest.C(t, func(t *gtest.T) {

frame/gins/gins_z_unit_server_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2+
//
3+
// This Source Code Form is subject to the terms of the MIT License.
4+
// If a copy of the MIT was not distributed with this file,
5+
// You can obtain one at https://github.com/gogf/gf.
6+
7+
package gins
8+
9+
import (
10+
"testing"
11+
12+
"github.com/gogf/gf/v2/net/ghttp"
13+
"github.com/gogf/gf/v2/os/gcfg"
14+
"github.com/gogf/gf/v2/os/gctx"
15+
"github.com/gogf/gf/v2/test/gtest"
16+
)
17+
18+
func Test_Server(t *testing.T) {
19+
gtest.C(t, func(t *gtest.T) {
20+
var (
21+
config = Config().GetAdapter().(*gcfg.AdapterFile)
22+
searchingPaths = config.GetPaths()
23+
serverConfigDir = gtest.DataPath("server")
24+
)
25+
t.AssertNE(serverConfigDir, "")
26+
t.AssertNil(config.SetPath(serverConfigDir))
27+
defer func() {
28+
t.AssertNil(config.SetPath(searchingPaths[0]))
29+
if len(searchingPaths) > 1 {
30+
t.AssertNil(config.AddPath(searchingPaths[1:]...))
31+
}
32+
}()
33+
34+
localInstances.Clear()
35+
defer localInstances.Clear()
36+
37+
config.Clear()
38+
defer config.Clear()
39+
40+
s := Server("tempByInstanceName")
41+
s.BindHandler("/", func(r *ghttp.Request) {
42+
r.Response.Write("hello")
43+
})
44+
s.SetDumpRouterMap(false)
45+
t.AssertNil(s.Start())
46+
defer t.AssertNil(s.Shutdown())
47+
48+
content := HttpClient().GetContent(gctx.New(), `http://127.0.0.1:8003/`)
49+
t.Assert(content, `hello`)
50+
})
51+
}

0 commit comments

Comments
 (0)