1
0
mirror of https://github.com/golang/go synced 2024-09-24 17:10:13 -06:00

net/http: make a test more paranoid & reliable on Windows, maybe.

Part of diagnosing issue 3050.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5707056
This commit is contained in:
Brad Fitzpatrick 2012-02-29 09:53:20 -08:00
parent f5df930618
commit 3684ae9da0

View File

@ -152,12 +152,19 @@ func TestFileServerCleans(t *testing.T) {
} }
} }
func mustRemoveAll(dir string) {
err := os.RemoveAll(dir)
if err != nil {
panic(err)
}
}
func TestFileServerImplicitLeadingSlash(t *testing.T) { func TestFileServerImplicitLeadingSlash(t *testing.T) {
tempDir, err := ioutil.TempDir("", "") tempDir, err := ioutil.TempDir("", "")
if err != nil { if err != nil {
t.Fatalf("TempDir: %v", err) t.Fatalf("TempDir: %v", err)
} }
defer os.RemoveAll(tempDir) defer mustRemoveAll(tempDir)
if err := ioutil.WriteFile(filepath.Join(tempDir, "foo.txt"), []byte("Hello world"), 0644); err != nil { if err := ioutil.WriteFile(filepath.Join(tempDir, "foo.txt"), []byte("Hello world"), 0644); err != nil {
t.Fatalf("WriteFile: %v", err) t.Fatalf("WriteFile: %v", err)
} }
@ -172,6 +179,7 @@ func TestFileServerImplicitLeadingSlash(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("ReadAll %s: %v", suffix, err) t.Fatalf("ReadAll %s: %v", suffix, err)
} }
res.Body.Close()
return string(b) return string(b)
} }
if s := get("/bar/"); !strings.Contains(s, ">foo.txt<") { if s := get("/bar/"); !strings.Contains(s, ">foo.txt<") {