1 Star 0 Fork 0

kaylee595 / gkaylee

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
testHttp_test.go 531 Bytes
AI 代码解读
一键复制 编辑 原始数据 按行查看 历史
kaylee595 提交于 2024-05-07 00:07 . 修改测试文件中的变量名
package gkaylee
import (
"github.com/stretchr/testify/assert"
"io"
"net/http"
"net/http/httptest"
"testing"
)
func TestTestHttpRequest(t *testing.T) {
want := []byte("pong")
mux := http.NewServeMux()
mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write(want)
assert.Equal(t, nil, err)
})
resp := TestHttpRequest(httptest.NewRequest("GET", "/ping", nil), mux)
defer resp.Body.Close()
actual, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
assert.Equal(t, want, actual)
}
Go
1
https://gitee.com/kaylee595/gkaylee.git
git@gitee.com:kaylee595/gkaylee.git
kaylee595
gkaylee
gkaylee
master

搜索帮助