Ai
2 Star 0 Fork 0

mirrors_sourcegraph/httpfstream

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
http_test.go 1010 Bytes
一键复制 编辑 原始数据 按行查看 历史
Quinn Slack 提交于 2013-09-19 05:03 +08:00 . Append/Follow
package httpfstream
import (
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"
)
type testServer struct {
*httptest.Server
dir string
}
func newTestServer() testServer {
dir, err := ioutil.TempDir("", "httpfstream")
if err != nil {
panic("TempDir: " + err.Error())
}
err = os.MkdirAll(dir, 0700)
if err != nil {
panic("MkdirAll: " + err.Error())
}
rootMux := http.NewServeMux()
h := New(dir)
h.Log = log.New(os.Stderr, "", 0)
rootMux.Handle("/", h)
return testServer{
Server: httptest.NewServer(rootMux),
dir: dir,
}
}
func (s testServer) close() {
s.Server.Close()
os.RemoveAll(s.dir)
}
func httpGET(t *testing.T, u *url.URL) string {
resp, err := http.Get(u.String())
if err != nil {
t.Fatalf("httpGET %s: %s", u, err)
}
defer resp.Body.Close()
return string(readAll(t, resp.Body))
}
func readAll(t *testing.T, rdr io.Reader) []byte {
data, err := ioutil.ReadAll(rdr)
if err != nil {
t.Fatal("ReadAll", err)
}
return data
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_sourcegraph/httpfstream.git
git@gitee.com:mirrors_sourcegraph/httpfstream.git
mirrors_sourcegraph
httpfstream
httpfstream
master

搜索帮助