Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
joy999 committed Oct 27, 2023
1 parent 9a2dfe6 commit a3233e8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions contrib/registry/nacos/nacos_z_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestWatch(t *testing.T) {
t.Assert(ok, true)
t.Assert(len(proceedResult), 1)
t.Assert(
sortEndpoints(proceedResult[0].GetEndpoints()),
allEndpoints(proceedResult),
gsvc.Endpoints{svc1.GetEndpoints()[0], svc2.GetEndpoints()[0]},
)

Expand All @@ -171,7 +171,7 @@ func TestWatch(t *testing.T) {
t.Assert(ok, true)
t.Assert(len(proceedResult), 1)
t.Assert(
sortEndpoints(proceedResult[0].GetEndpoints()),
allEndpoints(proceedResult),
gsvc.Endpoints{svc1.GetEndpoints()[0]},
)
t.AssertNil(watcher.Close())
Expand All @@ -183,6 +183,20 @@ func TestWatch(t *testing.T) {
})
}

func allEndpoints(services []gsvc.Service) gsvc.Endpoints {
m := map[gsvc.Endpoint]struct{}{}
for _, s := range services {
for _, ep := range s.GetEndpoints() {
m[ep] = struct{}{}
}
}
var endpoints gsvc.Endpoints
for ep := range m {
endpoints = append(endpoints, ep)
}
return sortEndpoints(endpoints)
}

func sortEndpoints(in gsvc.Endpoints) gsvc.Endpoints {
var endpoints gsvc.Endpoints
endpoints = append(endpoints, in...)
Expand Down

0 comments on commit a3233e8

Please sign in to comment.