summaryrefslogtreecommitdiff
path: root/libgo/go/http/response_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/http/response_test.go')
-rw-r--r--libgo/go/http/response_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/libgo/go/http/response_test.go b/libgo/go/http/response_test.go
index 1d4a2342358..86494bf4ae9 100644
--- a/libgo/go/http/response_test.go
+++ b/libgo/go/http/response_test.go
@@ -15,6 +15,7 @@ import (
"io/ioutil"
"reflect"
"testing"
+ "url"
)
type respTest struct {
@@ -395,3 +396,52 @@ func diff(t *testing.T, prefix string, have, want interface{}) {
}
}
}
+
+type responseLocationTest struct {
+ location string // Response's Location header or ""
+ requrl string // Response.Request.URL or ""
+ want string
+ wantErr os.Error
+}
+
+var responseLocationTests = []responseLocationTest{
+ {"/foo", "http://bar.com/baz", "http://bar.com/foo", nil},
+ {"http://foo.com/", "http://bar.com/baz", "http://foo.com/", nil},
+ {"", "http://bar.com/baz", "", ErrNoLocation},
+}
+
+func TestLocationResponse(t *testing.T) {
+ for i, tt := range responseLocationTests {
+ res := new(Response)
+ res.Header = make(Header)
+ res.Header.Set("Location", tt.location)
+ if tt.requrl != "" {
+ res.Request = &Request{}
+ var err os.Error
+ res.Request.URL, err = url.Parse(tt.requrl)
+ if err != nil {
+ t.Fatalf("bad test URL %q: %v", tt.requrl, err)
+ }
+ }
+
+ got, err := res.Location()
+ if tt.wantErr != nil {
+ if err == nil {
+ t.Errorf("%d. err=nil; want %q", i, tt.wantErr)
+ continue
+ }
+ if g, e := err.String(), tt.wantErr.String(); g != e {
+ t.Errorf("%d. err=%q; want %q", i, g, e)
+ continue
+ }
+ continue
+ }
+ if err != nil {
+ t.Errorf("%d. err=%q", i, err)
+ continue
+ }
+ if g, e := got.String(), tt.want; g != e {
+ t.Errorf("%d. Location=%q; want %q", i, g, e)
+ }
+ }
+}