diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-03-02 16:38:43 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-03-02 16:38:43 +0000 |
commit | 2d2d80b8bd963f59534897b3d51ef8bd546cb4bc (patch) | |
tree | efa0c55763b34cbc633bc494c2743d1b5d9aaff3 /libgo/go/net/http/httptest | |
parent | 2ad2700dbf70b2e49575f3f2307839a45cf2f71c (diff) | |
download | gcc-2d2d80b8bd963f59534897b3d51ef8bd546cb4bc.tar.gz |
libgo: Update to weekly.2012-02-14 release.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184798 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/net/http/httptest')
-rw-r--r-- | libgo/go/net/http/httptest/server.go | 4 | ||||
-rw-r--r-- | libgo/go/net/http/httptest/server_test.go | 29 |
2 files changed, 31 insertions, 2 deletions
diff --git a/libgo/go/net/http/httptest/server.go b/libgo/go/net/http/httptest/server.go index 5b02e143d4a..8d911f7575b 100644 --- a/libgo/go/net/http/httptest/server.go +++ b/libgo/go/net/http/httptest/server.go @@ -61,7 +61,7 @@ func newLocalListener() net.Listener { // When debugging a particular http server-based test, // this flag lets you run -// gotest -run=BrokenTest -httptest.serve=127.0.0.1:8000 +// go test -run=BrokenTest -httptest.serve=127.0.0.1:8000 // to start the broken server so you can interact with it manually. var serve = flag.String("httptest.serve", "", "if non-empty, httptest.NewServer serves on this address and blocks") @@ -95,7 +95,7 @@ func (s *Server) Start() { s.URL = "http://" + s.Listener.Addr().String() go s.Config.Serve(s.Listener) if *serve != "" { - fmt.Println(os.Stderr, "httptest: serving on", s.URL) + fmt.Fprintln(os.Stderr, "httptest: serving on", s.URL) select {} } } diff --git a/libgo/go/net/http/httptest/server_test.go b/libgo/go/net/http/httptest/server_test.go new file mode 100644 index 00000000000..500a9f0b800 --- /dev/null +++ b/libgo/go/net/http/httptest/server_test.go @@ -0,0 +1,29 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package httptest + +import ( + "io/ioutil" + "net/http" + "testing" +) + +func TestServer(t *testing.T) { + ts := NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("hello")) + })) + defer ts.Close() + res, err := http.Get(ts.URL) + if err != nil { + t.Fatal(err) + } + got, err := ioutil.ReadAll(res.Body) + if err != nil { + t.Fatal(err) + } + if string(got) != "hello" { + t.Errorf("got %q, want hello", string(got)) + } +} |