初始化
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package responsex_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.yun.ink/pkg/responsex"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestResponse(t *testing.T) {
|
||||
|
||||
go func() {
|
||||
g := gin.Default()
|
||||
g.GET("/", func(ctx *gin.Context) {
|
||||
responsex.GinSuccess(ctx, "hello world")
|
||||
})
|
||||
// 启动服务
|
||||
// http://localhost:8080
|
||||
g.Run(":8080")
|
||||
}()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// 测试响应
|
||||
// 发送请求
|
||||
// curl http://localhost:8080
|
||||
// 期望响应: {"code":200,"msg":"请求成功","data":"hello world"}
|
||||
|
||||
resp, err := http.Get("http://localhost:8080")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(string(b))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user