Skip to content

Commit

Permalink
[proxy]: Add dynamic service test
Browse files Browse the repository at this point in the history
  • Loading branch information
xxx7xxxx committed Aug 24, 2021
1 parent ab8c9b3 commit 963911f
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pkg/filter/proxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/megaease/easegress/pkg/context/contexttest"
"github.com/megaease/easegress/pkg/object/serviceregistry"
"github.com/megaease/easegress/pkg/util/hashtool"
"github.com/megaease/easegress/pkg/util/httpheader"
)
Expand Down Expand Up @@ -310,3 +311,48 @@ func TestStaticServers(t *testing.T) {
}
}
}

func TestDynamicService(t *testing.T) {
loadBalance := &LoadBalance{Policy: PolicyRandom}
s := &servers{
poolSpec: &PoolSpec{
LoadBalance: loadBalance,
},
}

instances := []*serviceregistry.ServiceInstanceSpec{
{
RegistryName: "registry-test1",
ServiceName: "service-test1",
InstanceID: "instance-test1",
HostIP: "127.0.0.1",
Port: 1111,
},
{
RegistryName: "registry-test1",
ServiceName: "service-test1",
InstanceID: "instance-test2",
HostIP: "127.0.0.1",
Port: 2222,
},
}

serviceInstanceSpecs := make(map[string]*serviceregistry.ServiceInstanceSpec)
for _, instance := range instances {
serviceInstanceSpecs[instance.Key()] = instance
}

s.useService(serviceInstanceSpecs)

wantStatic := &staticServers{
lb: *loadBalance,
servers: []*Server{
{URL: "http://127.0.0.1:1111"},
{URL: "http://127.0.0.1:2222"},
},
}

if !reflect.DeepEqual(wantStatic, s.static) {
t.Fatalf("want: %+v\ngot :%+v\n", wantStatic, s.static)
}
}

0 comments on commit 963911f

Please sign in to comment.