rename gdebug.TestData* -> gtest.Data*; add UT case for http server

This commit is contained in:
John Guo
2022-03-17 16:58:04 +08:00
parent b3e66d8023
commit bceb5fc7de
34 changed files with 167 additions and 152 deletions

View File

@ -58,10 +58,10 @@ func Server(name ...interface{}) *ghttp.Server {
}
}
}
// Server configuration.
// Automatically retrieve configuration by instance name.
serverConfigMap = Config().MustGet(
ctx,
fmt.Sprintf(`%s.%s`, configNodeName, server.GetName()),
fmt.Sprintf(`%s.%s`, configNodeName, instanceName),
).Map()
if len(serverConfigMap) == 0 {
serverConfigMap = Config().MustGet(ctx, configNodeName).Map()
@ -81,7 +81,7 @@ func Server(name ...interface{}) *ghttp.Server {
// Server logger configuration checks.
serverLoggerConfigMap = Config().MustGet(
ctx,
fmt.Sprintf(`%s.%s.%s`, configNodeName, server.GetName(), configNodeNameLogger),
fmt.Sprintf(`%s.%s.%s`, configNodeName, instanceName, configNodeNameLogger),
).Map()
if len(serverLoggerConfigMap) > 0 {
if err = server.Logger().SetConfigWithMap(serverLoggerConfigMap); err != nil {

View File

@ -12,7 +12,6 @@ import (
"testing"
"time"
"github.com/gogf/gf/v2/debug/gdebug"
"github.com/gogf/gf/v2/frame/gins"
"github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/v2/os/gfile"
@ -23,7 +22,7 @@ import (
var (
ctx = context.Background()
configContent = gfile.GetContents(
gdebug.TestDataPath("config", "config.toml"),
gtest.DataPath("config", "config.toml"),
)
)

View File

@ -10,7 +10,6 @@ import (
"testing"
"time"
"github.com/gogf/gf/v2/debug/gdebug"
"github.com/gogf/gf/v2/frame/gins"
"github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/v2/os/gfile"
@ -20,7 +19,7 @@ import (
func Test_Database(t *testing.T) {
databaseContent := gfile.GetContents(
gdebug.TestDataPath("database", "config.toml"),
gtest.DataPath("database", "config.toml"),
)
gtest.C(t, func(t *gtest.T) {
var err error

View File

@ -10,7 +10,6 @@ import (
"testing"
"time"
"github.com/gogf/gf/v2/debug/gdebug"
"github.com/gogf/gf/v2/frame/gins"
"github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/v2/os/gfile"
@ -20,7 +19,7 @@ import (
func Test_Redis(t *testing.T) {
redisContent := gfile.GetContents(
gdebug.TestDataPath("redis", "config.toml"),
gtest.DataPath("redis", "config.toml"),
)
gtest.C(t, func(t *gtest.T) {

View File

@ -0,0 +1,51 @@
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gins
import (
"testing"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/test/gtest"
)
func Test_Server(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
var (
config = Config().GetAdapter().(*gcfg.AdapterFile)
searchingPaths = config.GetPaths()
serverConfigDir = gtest.DataPath("server")
)
t.AssertNE(serverConfigDir, "")
t.AssertNil(config.SetPath(serverConfigDir))
defer func() {
t.AssertNil(config.SetPath(searchingPaths[0]))
if len(searchingPaths) > 1 {
t.AssertNil(config.AddPath(searchingPaths[1:]...))
}
}()
localInstances.Clear()
defer localInstances.Clear()
config.Clear()
defer config.Clear()
s := Server("tempByInstanceName")
s.BindHandler("/", func(r *ghttp.Request) {
r.Response.Write("hello")
})
s.SetDumpRouterMap(false)
t.AssertNil(s.Start())
defer t.AssertNil(s.Shutdown())
content := HttpClient().GetContent(gctx.New(), `http://127.0.0.1:8003/`)
t.Assert(content, `hello`)
})
}

View File

@ -11,7 +11,6 @@ import (
"fmt"
"testing"
"github.com/gogf/gf/v2/debug/gdebug"
"github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gtime"
@ -53,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 := gdebug.TestDataPath("view1")
dirPath := gtest.DataPath("view1")
Config().GetAdapter().(*gcfg.AdapterFile).SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml")))
defer Config().GetAdapter().(*gcfg.AdapterFile).ClearContent()
defer localInstances.Clear()
@ -75,7 +74,7 @@ func Test_View_Config(t *testing.T) {
})
// view1 test2
gtest.C(t, func(t *gtest.T) {
dirPath := gdebug.TestDataPath("view1")
dirPath := gtest.DataPath("view1")
Config().GetAdapter().(*gcfg.AdapterFile).SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml")))
defer Config().GetAdapter().(*gcfg.AdapterFile).ClearContent()
defer localInstances.Clear()
@ -97,7 +96,7 @@ func Test_View_Config(t *testing.T) {
})
// view2
gtest.C(t, func(t *gtest.T) {
dirPath := gdebug.TestDataPath("view2")
dirPath := gtest.DataPath("view2")
Config().GetAdapter().(*gcfg.AdapterFile).SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml")))
defer Config().GetAdapter().(*gcfg.AdapterFile).ClearContent()
defer localInstances.Clear()
@ -119,7 +118,7 @@ func Test_View_Config(t *testing.T) {
})
// view2
gtest.C(t, func(t *gtest.T) {
dirPath := gdebug.TestDataPath("view2")
dirPath := gtest.DataPath("view2")
Config().GetAdapter().(*gcfg.AdapterFile).SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml")))
defer Config().GetAdapter().(*gcfg.AdapterFile).ClearContent()
defer localInstances.Clear()

View File

@ -0,0 +1,4 @@
server:
address: ":8000"
tempByInstanceName:
address: ":8003"