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

Unified Diff: server/prpc/encoding_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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « server/prpc/encoding.go ('k') | server/prpc/error.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/prpc/encoding_test.go
diff --git a/server/prpc/encoding_test.go b/server/prpc/encoding_test.go
index 3a636a86fa38a89484c4912e0766466a4d1e6502..ef37eb07e615a26d94adf9e0de80dde92ebe6b43 100644
--- a/server/prpc/encoding_test.go
+++ b/server/prpc/encoding_test.go
@@ -5,20 +5,13 @@
package prpc
import (
- "fmt"
"net/http"
- "net/http/httptest"
"strings"
"testing"
"github.com/golang/protobuf/proto"
- "golang.org/x/net/context"
- "google.golang.org/grpc"
"google.golang.org/grpc/codes"
- "github.com/luci/luci-go/common/logging"
- "github.com/luci/luci-go/common/logging/memlogger"
-
. "github.com/luci/luci-go/common/testing/assertions"
. "github.com/smartystreets/goconvey/convey"
)
@@ -71,27 +64,26 @@ func TestEncoding(t *testing.T) {
test("foo/bar;q=0.1,{json}", formatJSONPB, nil)
// only unsupported types
- const err406 = "HTTP 406: Accept header: specified media types are not not supported"
+ const err406 = "pRPC: Accept header: specified media types are not not supported"
test(mtPRPC+"; boo=true", 0, err406)
test(mtPRPC+"; encoding=blah", 0, err406)
test("x", 0, err406)
test("x,y", 0, err406)
- test("x//y", 0, "HTTP 400: Accept header: expected token after slash")
+ test("x//y", 0, "pRPC: Accept header: expected token after slash")
})
- Convey("writeMessage", t, func() {
+ Convey("respondMessage", t, func() {
msg := &HelloReply{Message: "Hi"}
test := func(f format, body []byte, contentType string) {
Convey(contentType, func() {
- res := httptest.NewRecorder()
- err := writeMessage(res, msg, f)
- So(err, ShouldBeNil)
-
- So(res.Code, ShouldEqual, http.StatusOK)
- So(res.Body.Bytes(), ShouldResembleV, body)
- So(res.Header().Get("Content-Type"), ShouldEqual, contentType)
+ res := respondMessage(msg, f)
+ So(res.code, ShouldEqual, codes.OK)
+ So(res.header, ShouldResembleV, http.Header{
+ headerContentType: []string{contentType},
+ })
+ So(res.body, ShouldResembleV, body)
})
}
@@ -99,37 +91,7 @@ func TestEncoding(t *testing.T) {
So(err, ShouldBeNil)
test(formatBinary, msgBytes, mtPRPCBinary)
- test(formatJSONPB, []byte("{\n\t\"message\": \"Hi\"\n}\n"), mtPRPCJSNOPB)
+ test(formatJSONPB, []byte(csrfPrefix+"{\"message\":\"Hi\"}"), mtPRPCJSNOPB)
test(formatText, []byte("message: \"Hi\"\n"), mtPRPCText)
})
-
- Convey("writeError", t, func() {
- test := func(err error, status int, body string, logMsgs ...memlogger.LogEntry) {
- Convey(err.Error(), func() {
- c := context.Background()
- c = memlogger.Use(c)
- log := logging.Get(c).(*memlogger.MemLogger)
-
- rec := httptest.NewRecorder()
- writeError(c, rec, err)
- So(rec.Code, ShouldEqual, status)
- So(rec.Body.String(), ShouldEqual, body)
-
- actualMsgs := log.Messages()
- for i := range actualMsgs {
- actualMsgs[i].CallDepth = 0
- }
- So(actualMsgs, ShouldResembleV, logMsgs)
- })
- }
-
- test(Errorf(http.StatusNotFound, "not found"), http.StatusNotFound, "not found\n")
- test(grpc.Errorf(codes.NotFound, "not found"), http.StatusNotFound, "not found\n")
- test(
- fmt.Errorf("unhandled"),
- http.StatusInternalServerError,
- "Internal server error\n",
- memlogger.LogEntry{Level: logging.Error, Msg: "HTTP 500: unhandled"},
- )
- })
}
« no previous file with comments | « server/prpc/encoding.go ('k') | server/prpc/error.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698