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

Unified Diff: server/discovery/internal/testservices/discovery_test.go

Issue 1571393006: server/discovery: add discovery service (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@prpc-server
Patch Set: rebased 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/discovery/generate.go ('k') | server/discovery/internal/testservices/generate.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/discovery/internal/testservices/discovery_test.go
diff --git a/server/discovery/internal/testservices/discovery_test.go b/server/discovery/internal/testservices/discovery_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..0fd4a385eec5c4c2009709c159765dfa050b9a1a
--- /dev/null
+++ b/server/discovery/internal/testservices/discovery_test.go
@@ -0,0 +1,76 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package testservices
+
+// This test is not in discovery because it needs to a test services
+// in different directories.
+// However, a generated service depends on server/discovery
+// and a test in server/discovery depends on the service.
+// This creates a a cyclic import.
+// To break the cycle, we move this test from server/discovery.
+
+import (
+ "testing"
+
+ "github.com/golang/protobuf/proto"
+ "golang.org/x/net/context"
+
+ "github.com/luci/luci-go/common/proto/google/descriptor"
+ "github.com/luci/luci-go/server/discovery"
+
+ . "github.com/luci/luci-go/common/testing/assertions"
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+// force test services registration.
+var _ = CalcServer(nil)
+
+func TestDiscovery(t *testing.T) {
+ Convey("Discovery", t, func() {
+
+ server, err := discovery.New(
+ "discovery.Discovery",
+ "testservices.Greeter",
+ "testservices.Calc",
+ )
+ So(err, ShouldBeNil)
+
+ c := context.Background()
+ res, err := server.Describe(c, nil)
+ So(err, ShouldBeNil)
+
+ So(res.Services, ShouldResembleV, []string{
+ "discovery.Discovery",
+ "testservices.Greeter",
+ "testservices.Calc",
+ })
+
+ desc := &descriptor.FileDescriptorSet{}
+ err = proto.Unmarshal(res.FileDescriptionSet, desc)
+ So(err, ShouldBeNil)
+
+ // this checks that file deduplication actually works.
+ So(len(desc.File), ShouldEqual, 2)
+
+ discovery := desc.FindService("discovery.Discovery")
+ So(discovery, ShouldNotBeNil)
+
+ calc := desc.FindService("testservices.Calc")
+ So(calc, ShouldNotBeNil)
+
+ serviceDesc := desc.FindService("testservices.Greeter")
+ So(serviceDesc, ShouldNotBeNil)
+
+ sayHelloDesc := serviceDesc.FindMethod("SayHello")
+ So(sayHelloDesc, ShouldNotBeNil)
+
+ So(sayHelloDesc.GetInputType(), ShouldEqual, ".testservices.HelloRequest")
+ helloReq := desc.FindMessage("testservices.HelloRequest")
+ So(helloReq, ShouldNotBeNil)
+ So(helloReq.Field, ShouldHaveLength, 1)
+ So(helloReq.Field[0].GetName(), ShouldEqual, "name")
+ So(helloReq.Field[0].GetType(), ShouldEqual, descriptor.FieldDescriptorProto_TYPE_STRING)
+ })
+}
« no previous file with comments | « server/discovery/generate.go ('k') | server/discovery/internal/testservices/generate.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698