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

Unified Diff: server/prpc/server_test.go

Issue 1636873006: server/prpc: updated server according to protocol (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Removed some panics, malformed JSON now errors. 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
Index: server/prpc/server_test.go
diff --git a/server/prpc/server_test.go b/server/prpc/server_test.go
index 5ab9407314d2dca454f5d691bce48957adedfc63..c7f2e814a846a6afe9697491e189eb11576b5b83 100644
--- a/server/prpc/server_test.go
+++ b/server/prpc/server_test.go
@@ -8,6 +8,7 @@ import (
"bytes"
"net/http"
"net/http/httptest"
+ "strconv"
"testing"
"github.com/julienschmidt/httprouter"
@@ -15,6 +16,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
+ "github.com/luci/luci-go/common/prpc"
"github.com/luci/luci-go/server/middleware"
. "github.com/luci/luci-go/common/testing/assertions"
@@ -66,14 +68,18 @@ func TestServer(t *testing.T) {
server.InstallHandlers(r, middleware.TestingBase(c))
res := httptest.NewRecorder()
hiMsg := bytes.NewBufferString(`name: "Lucy"`)
- req, err := http.NewRequest("POST", "http://localhost/prpc/prpc.Greeter/SayHello", hiMsg)
+ req, err := http.NewRequest("POST", "/prpc/prpc.Greeter/SayHello", hiMsg)
So(err, ShouldBeNil)
req.Header.Set("Content-Type", mtPRPCText)
+ invalidArgument := strconv.Itoa(int(codes.InvalidArgument))
+ unimplemented := strconv.Itoa(int(codes.Unimplemented))
+
Convey("Works", func() {
req.Header.Set("Accept", mtPRPCText)
r.ServeHTTP(res, req)
So(res.Code, ShouldEqual, http.StatusOK)
+ So(res.Header().Get(prpc.HeaderGRPCCode), ShouldEqual, "0")
So(res.Body.String(), ShouldEqual, "message: \"Hello Lucy\"\n")
})
@@ -81,26 +87,43 @@ func TestServer(t *testing.T) {
req.Header.Set("Accept", "blah")
r.ServeHTTP(res, req)
So(res.Code, ShouldEqual, http.StatusNotAcceptable)
+ So(res.Header().Get(prpc.HeaderGRPCCode), ShouldEqual, invalidArgument)
})
Convey("Invalid header", func() {
req.Header.Set("X-Bin", "zzz")
r.ServeHTTP(res, req)
So(res.Code, ShouldEqual, http.StatusBadRequest)
+ So(res.Header().Get(prpc.HeaderGRPCCode), ShouldEqual, invalidArgument)
})
Convey("Malformed request message", func() {
hiMsg.WriteString("\nblah")
r.ServeHTTP(res, req)
So(res.Code, ShouldEqual, http.StatusBadRequest)
+ So(res.Header().Get(prpc.HeaderGRPCCode), ShouldEqual, invalidArgument)
})
Convey("Invalid request message", func() {
hiMsg.Reset()
r.ServeHTTP(res, req)
So(res.Code, ShouldEqual, http.StatusBadRequest)
+ So(res.Header().Get(prpc.HeaderGRPCCode), ShouldEqual, invalidArgument)
So(res.Body.String(), ShouldEqual, "Name unspecified\n")
})
+
+ Convey("no such service", func() {
+ req.URL.Path = "/prpc/xxx/SayHello"
+ r.ServeHTTP(res, req)
+ So(res.Code, ShouldEqual, http.StatusNotImplemented)
+ So(res.Header().Get(prpc.HeaderGRPCCode), ShouldEqual, unimplemented)
+ })
+ Convey("no such method", func() {
+ req.URL.Path = "/prpc/prpc.Greeter/xxx"
+ r.ServeHTTP(res, req)
+ So(res.Code, ShouldEqual, http.StatusNotImplemented)
+ So(res.Header().Get(prpc.HeaderGRPCCode), ShouldEqual, unimplemented)
+ })
})
})
}
« server/prpc/server.go ('K') | « server/prpc/server.go ('k') | server/prpc/service.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698