| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package prpc | 5 package prpc |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "encoding/base64" | 9 "encoding/base64" |
| 10 "io/ioutil" | 10 "io/ioutil" |
| 11 "net/http" | 11 "net/http" |
| 12 "testing" | 12 "testing" |
| 13 "time" | 13 "time" |
| 14 | 14 |
| 15 "github.com/golang/protobuf/proto" | 15 "github.com/golang/protobuf/proto" |
| 16 "golang.org/x/net/context" | 16 "golang.org/x/net/context" |
| 17 "google.golang.org/grpc/metadata" | 17 "google.golang.org/grpc/metadata" |
| 18 | 18 |
| 19 "github.com/luci/luci-go/common/clock/testclock" | 19 "github.com/luci/luci-go/common/clock/testclock" |
| 20 prpccommon "github.com/luci/luci-go/common/prpc" |
| 20 | 21 |
| 21 . "github.com/luci/luci-go/common/testing/assertions" | 22 . "github.com/luci/luci-go/common/testing/assertions" |
| 22 . "github.com/smartystreets/goconvey/convey" | 23 . "github.com/smartystreets/goconvey/convey" |
| 23 ) | 24 ) |
| 24 | 25 |
| 25 func TestDecoding(t *testing.T) { | 26 func TestDecoding(t *testing.T) { |
| 26 t.Parallel() | 27 t.Parallel() |
| 27 | 28 |
| 28 Convey("requestFormat", t, func() { | 29 Convey("requestFormat", t, func() { |
| 29 test := func(contentType string, expectedFormat format, expected
Err interface{}) { | 30 test := func(contentType string, expectedFormat format, expected
Err interface{}) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 139 |
| 139 Convey("parseHeader", t, func() { | 140 Convey("parseHeader", t, func() { |
| 140 c := context.Background() | 141 c := context.Background() |
| 141 | 142 |
| 142 header := func(name, value string) http.Header { | 143 header := func(name, value string) http.Header { |
| 143 return http.Header{ | 144 return http.Header{ |
| 144 name: []string{value}, | 145 name: []string{value}, |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 | 148 |
| 148 » » Convey(headerTimeout, func() { | 149 » » Convey(prpccommon.HeaderTimeout, func() { |
| 149 Convey("Works", func() { | 150 Convey("Works", func() { |
| 150 now := time.Date(2016, 1, 1, 0, 0, 0, 0, time.UT
C) | 151 now := time.Date(2016, 1, 1, 0, 0, 0, 0, time.UT
C) |
| 151 c, _ = testclock.UseTime(c, now) | 152 c, _ = testclock.UseTime(c, now) |
| 152 | 153 |
| 153 » » » » c, err := parseHeader(c, header(headerTimeout, "
1M")) | 154 » » » » c, err := parseHeader(c, header(prpccommon.Heade
rTimeout, "1M")) |
| 154 So(err, ShouldBeNil) | 155 So(err, ShouldBeNil) |
| 155 | 156 |
| 156 deadline, ok := c.Deadline() | 157 deadline, ok := c.Deadline() |
| 157 So(ok, ShouldBeTrue) | 158 So(ok, ShouldBeTrue) |
| 158 So(deadline, ShouldHappenWithin, time.Second, no
w.Add(time.Minute)) | 159 So(deadline, ShouldHappenWithin, time.Second, no
w.Add(time.Minute)) |
| 159 }) | 160 }) |
| 160 | 161 |
| 161 Convey("Fails", func() { | 162 Convey("Fails", func() { |
| 162 » » » » c2, err := parseHeader(c, header(headerTimeout,
"blah")) | 163 » » » » c2, err := parseHeader(c, header(prpccommon.Head
erTimeout, "blah")) |
| 163 So(c2, ShouldEqual, c) | 164 So(c2, ShouldEqual, c) |
| 164 » » » » So(err, ShouldErrLike, headerTimeout+` header: u
nit is not recognized: "blah"`) | 165 » » » » So(err, ShouldErrLike, prpccommon.HeaderTimeout+
` header: unit is not recognized: "blah"`) |
| 165 }) | 166 }) |
| 166 }) | 167 }) |
| 167 | 168 |
| 168 Convey("Content-Type", func() { | 169 Convey("Content-Type", func() { |
| 169 c, err := parseHeader(c, header("Content-Type", "blah")) | 170 c, err := parseHeader(c, header("Content-Type", "blah")) |
| 170 So(err, ShouldBeNil) | 171 So(err, ShouldBeNil) |
| 171 _, ok := metadata.FromContext(c) | 172 _, ok := metadata.FromContext(c) |
| 172 So(ok, ShouldBeFalse) | 173 So(ok, ShouldBeFalse) |
| 173 }) | 174 }) |
| 174 | 175 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 }) | 220 }) |
| 220 Convey("Fails", func() { | 221 Convey("Fails", func() { |
| 221 c2, err := parseHeader(c, header("Name-B
in", "zzz")) | 222 c2, err := parseHeader(c, header("Name-B
in", "zzz")) |
| 222 So(c2, ShouldEqual, c) | 223 So(c2, ShouldEqual, c) |
| 223 So(err, ShouldErrLike, "Name-Bin header:
illegal base64 data at input byte 0") | 224 So(err, ShouldErrLike, "Name-Bin header:
illegal base64 data at input byte 0") |
| 224 }) | 225 }) |
| 225 }) | 226 }) |
| 226 }) | 227 }) |
| 227 }) | 228 }) |
| 228 } | 229 } |
| OLD | NEW |