MCPcopy
hub / github.com/micro/go-micro / TestMemoryRegistry

Function TestMemoryRegistry

registry/memory_test.go:77–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75)
76
77func TestMemoryRegistry(t *testing.T) {
78 m := NewMemoryRegistry()
79
80 fn := func(k string, v []*Service) {
81 services, err := m.GetService(k)
82 if err != nil {
83 t.Errorf("Unexpected error getting service %s: %v", k, err)
84 }
85
86 if len(services) != len(v) {
87 t.Errorf("Expected %d services for %s, got %d", len(v), k, len(services))
88 }
89
90 for _, service := range v {
91 var seen bool
92 for _, s := range services {
93 if s.Version == service.Version {
94 seen = true
95 break
96 }
97 }
98 if !seen {
99 t.Errorf("expected to find version %s", service.Version)
100 }
101 }
102 }
103
104 // register data
105 for _, v := range testData {
106 serviceCount := 0
107 for _, service := range v {
108 if err := m.Register(service); err != nil {
109 t.Errorf("Unexpected register error: %v", err)
110 }
111 serviceCount++
112 // after the service has been registered we should be able to query it
113 services, err := m.GetService(service.Name)
114 if err != nil {
115 t.Errorf("Unexpected error getting service %s: %v", service.Name, err)
116 }
117 if len(services) != serviceCount {
118 t.Errorf("Expected %d services for %s, got %d", serviceCount, service.Name, len(services))
119 }
120 }
121 }
122
123 // using test data
124 for k, v := range testData {
125 fn(k, v)
126 }
127
128 services, err := m.ListServices()
129 if err != nil {
130 t.Errorf("Unexpected error when listing services: %v", err)
131 }
132
133 totalServiceCount := 0
134 for _, testSvc := range testData {

Callers

nothing calls this directly

Calls 6

NewMemoryRegistryFunction · 0.85
GetServiceMethod · 0.65
RegisterMethod · 0.65
ListServicesMethod · 0.65
DeregisterMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…