grpc_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package naming
  15. import (
  16. "reflect"
  17. "testing"
  18. "google.golang.org/grpc/naming"
  19. "github.com/coreos/etcd/integration"
  20. "github.com/coreos/etcd/pkg/testutil"
  21. )
  22. func TestGRPCResolver(t *testing.T) {
  23. defer testutil.AfterTest(t)
  24. clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
  25. defer clus.Terminate(t)
  26. r := GRPCResolver{
  27. Client: clus.RandClient(),
  28. }
  29. w, err := r.Resolve("foo")
  30. if err != nil {
  31. t.Fatal("failed to resolve foo", err)
  32. }
  33. defer w.Close()
  34. err = r.Add("foo", "127.0.0.1", "metadata")
  35. if err != nil {
  36. t.Fatal("failed to add foo", err)
  37. }
  38. us, err := w.Next()
  39. if err != nil {
  40. t.Fatal("failed to get udpate", err)
  41. }
  42. wu := &naming.Update{
  43. Op: naming.Add,
  44. Addr: "127.0.0.1",
  45. Metadata: "metadata",
  46. }
  47. if !reflect.DeepEqual(us[0], wu) {
  48. t.Fatalf("up = %#v, want %#v", us[0], wu)
  49. }
  50. err = r.Delete("foo")
  51. us, err = w.Next()
  52. if err != nil {
  53. t.Fatal("failed to get udpate", err)
  54. }
  55. wu = &naming.Update{
  56. Op: naming.Delete,
  57. }
  58. if !reflect.DeepEqual(us[0], wu) {
  59. t.Fatalf("up = %#v, want %#v", us[0], wu)
  60. }
  61. }