implement fakeIPVS update virtual server

This commit is contained in:
m1093782566 2017-09-28 21:59:55 +08:00
parent 6a2ec70a2d
commit 8f6f382003
2 changed files with 20 additions and 1 deletions

View File

@ -77,11 +77,13 @@ func (f *FakeIPVS) AddVirtualServer(serv *utilipvs.VirtualServer) error {
return nil
}
//UpdateVirtualServer is an empty implementation
//UpdateVirtualServer is a fake implementation, it updates the VirtualServer in the cache store.
func (f *FakeIPVS) UpdateVirtualServer(serv *utilipvs.VirtualServer) error {
if serv == nil {
return fmt.Errorf("Failed to update service, service can't be nil")
}
key := toServiceKey(serv)
f.Services[key] = serv
return nil
}

View File

@ -31,6 +31,7 @@ func TestVirtualServer(t *testing.T) {
Address: net.ParseIP("1.2.3.4"),
Port: uint16(80),
Protocol: string("TCP"),
Flags: utilipvs.FlagHashed,
}
err := fake.AddVirtualServer(vs1)
if err != nil {
@ -44,6 +45,22 @@ func TestVirtualServer(t *testing.T) {
if !vs1.Equal(got1) {
t.Errorf("Expect virtual server: %v, got: %v", vs1, got1)
}
// Update virtual server
vs12 := &utilipvs.VirtualServer{
Address: net.ParseIP("1.2.3.4"),
Port: uint16(80),
Protocol: string("TCP"),
Flags: utilipvs.FlagPersistent,
}
err = fake.UpdateVirtualServer(vs12)
if err != nil {
t.Errorf("Fail to update virutal server, error: %v", err)
}
// Check the updated virtual server
got12, err := fake.GetVirtualServer(vs1)
if !got12.Equal(vs12) {
t.Errorf("Expect virutal server: %v, got: %v", vs12, got12)
}
// Add another virtual server
vs2 := &utilipvs.VirtualServer{
Address: net.ParseIP("10::40"),