| 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 "fmt" | |
| 9 "net/http" | 8 "net/http" |
| 10 "testing" | 9 "testing" |
| 11 | 10 |
| 12 "google.golang.org/grpc" | |
| 13 "google.golang.org/grpc/codes" | |
| 14 | |
| 15 . "github.com/smartystreets/goconvey/convey" | 11 . "github.com/smartystreets/goconvey/convey" |
| 16 ) | 12 ) |
| 17 | 13 |
| 18 func TestError(t *testing.T) { | 14 func TestError(t *testing.T) { |
| 19 t.Parallel() | 15 t.Parallel() |
| 20 | 16 |
| 21 Convey("ErrorCode", t, func() { | |
| 22 status := ErrorStatus(nil) | |
| 23 So(status, ShouldEqual, http.StatusOK) | |
| 24 | |
| 25 status = ErrorStatus(grpc.Errorf(codes.NotFound, "Not found")) | |
| 26 So(status, ShouldEqual, http.StatusNotFound) | |
| 27 | |
| 28 status = ErrorStatus(withStatus(fmt.Errorf(""), http.StatusBadRe
quest)) | |
| 29 So(status, ShouldEqual, http.StatusBadRequest) | |
| 30 | |
| 31 status = ErrorStatus(fmt.Errorf("unhandled")) | |
| 32 So(status, ShouldEqual, http.StatusInternalServerError) | |
| 33 }) | |
| 34 | |
| 35 Convey("ErrorDesc", t, func() { | |
| 36 So(ErrorDesc(nil), ShouldEqual, "") | |
| 37 | |
| 38 err := Errorf(http.StatusNotFound, "not found") | |
| 39 So(ErrorDesc(err), ShouldEqual, "not found") | |
| 40 | |
| 41 err = grpc.Errorf(codes.NotFound, "not found") | |
| 42 So(ErrorDesc(err), ShouldEqual, "not found") | |
| 43 | |
| 44 err = withStatus(grpc.Errorf(codes.NotFound, "not found"), http.
StatusNotFound) | |
| 45 So(ErrorDesc(err), ShouldEqual, "not found") | |
| 46 | |
| 47 err = fmt.Errorf("not found") | |
| 48 So(ErrorDesc(err), ShouldEqual, "not found") | |
| 49 }) | |
| 50 | |
| 51 Convey("withStatus", t, func() { | 17 Convey("withStatus", t, func() { |
| 52 Convey("withStatus(nil, *) returns nil", func() { | 18 Convey("withStatus(nil, *) returns nil", func() { |
| 53 So(withStatus(nil, http.StatusBadRequest), ShouldBeNil) | 19 So(withStatus(nil, http.StatusBadRequest), ShouldBeNil) |
| 54 }) | 20 }) |
| 55 }) | 21 }) |
| 56 } | 22 } |
| OLD | NEW |