mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-22 16:40:20 +08:00
46 lines
855 B
Go
46 lines
855 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/zhufuyi/sponge/configs"
|
|
"github.com/zhufuyi/sponge/internal/config"
|
|
"github.com/zhufuyi/sponge/pkg/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestHTTPServer(t *testing.T) {
|
|
err := config.Init(configs.Path("serverNameExample.yml"))
|
|
t.Log(err)
|
|
|
|
defer func() {
|
|
if e := recover(); e != nil {
|
|
t.Log("ignore connect mysql error info")
|
|
}
|
|
}()
|
|
|
|
port, _ := utils.GetAvailablePort()
|
|
addr := fmt.Sprintf(":%d", port)
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
server := NewHTTPServer(addr,
|
|
WithHTTPReadTimeout(time.Second),
|
|
WithHTTPWriteTimeout(time.Second),
|
|
WithHTTPIsProd(true),
|
|
)
|
|
assert.NotNil(t, server)
|
|
|
|
str := server.String()
|
|
assert.NotEmpty(t, str)
|
|
|
|
go server.Start()
|
|
|
|
time.Sleep(time.Second)
|
|
err = server.Stop()
|
|
assert.NoError(t, err)
|
|
}
|