| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package testservices | 5 package testservices |
| 6 | 6 |
| 7 // This test is not in discovery because it needs to a test services | 7 // This test is not in discovery because it needs to a test services |
| 8 // in different directories. | 8 // in different directories. |
| 9 // However, a generated service depends on grpc/discovery | 9 // However, a generated service depends on grpc/discovery |
| 10 // and a test in grpc/discovery depends on the service. | 10 // and a test in grpc/discovery depends on the service. |
| 11 // This creates a a cyclic import. | 11 // This creates a a cyclic import. |
| 12 // To break the cycle, we move this test from grpc/discovery. | 12 // To break the cycle, we move this test from grpc/discovery. |
| 13 | 13 |
| 14 import ( | 14 import ( |
| 15 "testing" | 15 "testing" |
| 16 | 16 |
| 17 "golang.org/x/net/context" | 17 "golang.org/x/net/context" |
| 18 | 18 |
| 19 » "github.com/luci/luci-go/common/proto/google/descriptor" | 19 » "github.com/luci/luci-go/common/proto/google/descutil" |
| 20 "github.com/luci/luci-go/grpc/discovery" | 20 "github.com/luci/luci-go/grpc/discovery" |
| 21 | 21 |
| 22 "google.golang.org/genproto/protobuf" |
| 23 |
| 22 . "github.com/smartystreets/goconvey/convey" | 24 . "github.com/smartystreets/goconvey/convey" |
| 23 ) | 25 ) |
| 24 | 26 |
| 25 // force test services registration. | 27 // force test services registration. |
| 26 var _ = CalcServer(nil) | 28 var _ = CalcServer(nil) |
| 27 | 29 |
| 28 func TestDiscovery(t *testing.T) { | 30 func TestDiscovery(t *testing.T) { |
| 29 Convey("Discovery", t, func() { | 31 Convey("Discovery", t, func() { |
| 30 | 32 |
| 31 server, err := discovery.New( | 33 server, err := discovery.New( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 43 "discovery.Discovery", | 45 "discovery.Discovery", |
| 44 "testservices.Greeter", | 46 "testservices.Greeter", |
| 45 "testservices.Calc", | 47 "testservices.Calc", |
| 46 }) | 48 }) |
| 47 | 49 |
| 48 desc := res.Description | 50 desc := res.Description |
| 49 | 51 |
| 50 // this checks that file deduplication actually works. | 52 // this checks that file deduplication actually works. |
| 51 So(len(desc.File), ShouldEqual, 3) | 53 So(len(desc.File), ShouldEqual, 3) |
| 52 | 54 |
| 53 » » _, discoveryIndex := desc.FindService("discovery.Discovery") | 55 » » _, discoveryIndex := descutil.FindService(desc, "discovery.Disco
very") |
| 54 So(discoveryIndex, ShouldNotEqual, -1) | 56 So(discoveryIndex, ShouldNotEqual, -1) |
| 55 | 57 |
| 56 » » _, calcIndex := desc.FindService("testservices.Calc") | 58 » » _, calcIndex := descutil.FindService(desc, "testservices.Calc") |
| 57 So(calcIndex, ShouldNotEqual, -1) | 59 So(calcIndex, ShouldNotEqual, -1) |
| 58 | 60 |
| 59 » » file, greeterIndex := desc.FindService("testservices.Greeter") | 61 » » file, greeterIndex := descutil.FindService(desc, "testservices.G
reeter") |
| 60 So(greeterIndex, ShouldNotEqual, -1) | 62 So(greeterIndex, ShouldNotEqual, -1) |
| 61 greeter := file.Service[greeterIndex] | 63 greeter := file.Service[greeterIndex] |
| 62 | 64 |
| 63 » » sayHelloIndex := greeter.FindMethod("SayHello") | 65 » » sayHelloIndex := descutil.FindMethodForService(greeter, "SayHell
o") |
| 64 So(sayHelloIndex, ShouldNotEqual, -1) | 66 So(sayHelloIndex, ShouldNotEqual, -1) |
| 65 sayHello := greeter.Method[sayHelloIndex] | 67 sayHello := greeter.Method[sayHelloIndex] |
| 66 | 68 |
| 67 So(sayHello.GetInputType(), ShouldEqual, ".testservices.HelloReq
uest") | 69 So(sayHello.GetInputType(), ShouldEqual, ".testservices.HelloReq
uest") |
| 68 » » _, obj, _ := desc.Resolve("testservices.HelloRequest") | 70 » » _, obj, _ := descutil.Resolve(desc, "testservices.HelloRequest") |
| 69 So(obj, ShouldNotBeNil) | 71 So(obj, ShouldNotBeNil) |
| 70 helloReq := obj.(*descriptor.DescriptorProto) | 72 helloReq := obj.(*descriptor.DescriptorProto) |
| 71 So(helloReq, ShouldNotBeNil) | 73 So(helloReq, ShouldNotBeNil) |
| 72 So(helloReq.Field, ShouldHaveLength, 1) | 74 So(helloReq.Field, ShouldHaveLength, 1) |
| 73 So(helloReq.Field[0].GetName(), ShouldEqual, "name") | 75 So(helloReq.Field[0].GetName(), ShouldEqual, "name") |
| 74 So(helloReq.Field[0].GetType(), ShouldEqual, descriptor.FieldDes
criptorProto_TYPE_STRING) | 76 So(helloReq.Field[0].GetType(), ShouldEqual, descriptor.FieldDes
criptorProto_TYPE_STRING) |
| 75 }) | 77 }) |
| 76 } | 78 } |
| OLD | NEW |