mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-21 20:13:22 +00:00
Merge pull request #783 from kiyonlin/improve-test
👷 improve app and prefork test cases
This commit is contained in:
commit
247485ae84
4
app.go
4
app.go
@ -706,9 +706,9 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
|
||||
addr = "https://" + host + ":" + port
|
||||
}
|
||||
|
||||
isPrefork := "disabled"
|
||||
isPrefork := "Disabled"
|
||||
if app.config.Prefork {
|
||||
isPrefork = "enabled"
|
||||
isPrefork = "Enabled"
|
||||
}
|
||||
|
||||
out := colorable.NewColorableStdout()
|
||||
|
40
app_test.go
40
app_test.go
@ -433,15 +433,29 @@ func Test_App_New(t *testing.T) {
|
||||
appConfig.Get("/", testEmptyHandler)
|
||||
}
|
||||
|
||||
func Test_App_Shutdown(t *testing.T) {
|
||||
func Test_App_Config(t *testing.T) {
|
||||
app := New(Config{
|
||||
DisableStartupMessage: true,
|
||||
})
|
||||
if err := app.Shutdown(); err != nil {
|
||||
if err.Error() != "shutdown: server is not running" {
|
||||
t.Fatal()
|
||||
utils.AssertEqual(t, true, app.Config().DisableStartupMessage)
|
||||
}
|
||||
|
||||
func Test_App_Shutdown(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
app := New(Config{
|
||||
DisableStartupMessage: true,
|
||||
})
|
||||
utils.AssertEqual(t, true, app.Shutdown() == nil)
|
||||
})
|
||||
|
||||
t.Run("no server", func(t *testing.T) {
|
||||
app := &App{}
|
||||
if err := app.Shutdown(); err != nil {
|
||||
if err.Error() != "shutdown: server is not running" {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// go test -run Test_App_Static_Index_Default
|
||||
@ -750,7 +764,9 @@ func Test_App_Next_Method(t *testing.T) {
|
||||
|
||||
// go test -run Test_App_Listen
|
||||
func Test_App_Listen(t *testing.T) {
|
||||
app := New()
|
||||
app := New(Config{DisableStartupMessage: true})
|
||||
|
||||
utils.AssertEqual(t, false, app.Listen(":99999") == nil)
|
||||
|
||||
go func() {
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
@ -758,13 +774,6 @@ func Test_App_Listen(t *testing.T) {
|
||||
}()
|
||||
|
||||
utils.AssertEqual(t, nil, app.Listen(":4003"))
|
||||
|
||||
go func() {
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
utils.AssertEqual(t, nil, app.Shutdown())
|
||||
}()
|
||||
|
||||
utils.AssertEqual(t, nil, app.Listen(":4010"))
|
||||
}
|
||||
|
||||
// go test -run Test_App_Listener
|
||||
@ -990,3 +999,8 @@ func Test_App_SmallReadBuffer(t *testing.T) {
|
||||
|
||||
utils.AssertEqual(t, nil, app.Listen(":4006"))
|
||||
}
|
||||
|
||||
func Test_App_Master_Process_Show_Startup_Message(t *testing.T) {
|
||||
New(Config{Prefork: true}).
|
||||
startupMessage(":3000", true, "")
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ func Test_App_Prefork_Child_Process(t *testing.T) {
|
||||
// Reset test var
|
||||
testPreforkMaster = true
|
||||
|
||||
utils.AssertEqual(t, nil, os.Setenv(envPreforkChildKey, envPreforkChildVal))
|
||||
defer os.Setenv(envPreforkChildKey, "")
|
||||
setupIsChild(t)
|
||||
defer teardownIsChild(t)
|
||||
|
||||
app := New()
|
||||
|
||||
@ -64,8 +64,8 @@ func Test_App_Prefork_Master_Process(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_App_Prefork_Child_Process_Never_Show_Startup_Message(t *testing.T) {
|
||||
utils.AssertEqual(t, nil, os.Setenv(envPreforkChildKey, envPreforkChildVal))
|
||||
defer os.Setenv(envPreforkChildKey, "")
|
||||
setupIsChild(t)
|
||||
defer teardownIsChild(t)
|
||||
|
||||
rescueStdout := os.Stdout
|
||||
defer func() { os.Stdout = rescueStdout }()
|
||||
@ -83,3 +83,11 @@ func Test_App_Prefork_Child_Process_Never_Show_Startup_Message(t *testing.T) {
|
||||
utils.AssertEqual(t, nil, err)
|
||||
utils.AssertEqual(t, 0, len(out))
|
||||
}
|
||||
|
||||
func setupIsChild(t *testing.T) {
|
||||
utils.AssertEqual(t, nil, os.Setenv(envPreforkChildKey, envPreforkChildVal))
|
||||
}
|
||||
|
||||
func teardownIsChild(t *testing.T) {
|
||||
utils.AssertEqual(t, nil, os.Setenv(envPreforkChildKey, ""))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user