Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: server/prpc/error_test.go

Issue 1605363002: common/prpc, tools/cmd/cproto: prpc client (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: rebased and addressed comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « server/prpc/error.go ('k') | server/prpc/method.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 }
OLDNEW
« no previous file with comments | « server/prpc/error.go ('k') | server/prpc/method.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698