mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-29 19:52:04 +08:00
46 lines
855 B
Go
46 lines
855 B
Go
package handlerfunc
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/zhufuyi/sponge/pkg/utils"
|
|
)
|
|
|
|
func TestCheckHealth(t *testing.T) {
|
|
serverAddr, requestAddr := utils.GetLocalHTTPAddrPairs()
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
r := gin.New()
|
|
r.GET("/health", CheckHealth)
|
|
|
|
go func() {
|
|
_ = r.Run(serverAddr)
|
|
}()
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
|
resp, err := http.Get(requestAddr + "/health")
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, resp)
|
|
}
|
|
|
|
func TestPing(t *testing.T) {
|
|
serverAddr, requestAddr := utils.GetLocalHTTPAddrPairs()
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
r := gin.New()
|
|
r.GET("/ping", Ping)
|
|
|
|
go func() {
|
|
_ = r.Run(serverAddr)
|
|
}()
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
|
resp, err := http.Get(requestAddr + "/ping")
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, resp)
|
|
}
|