diff --git a/pkg/util/ipvs/testing/fake.go b/pkg/util/ipvs/testing/fake.go index 6710ed423cf..455d26f6a84 100644 --- a/pkg/util/ipvs/testing/fake.go +++ b/pkg/util/ipvs/testing/fake.go @@ -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 } diff --git a/pkg/util/ipvs/testing/fake_test.go b/pkg/util/ipvs/testing/fake_test.go index ea9d0a19503..2682bf25825 100644 --- a/pkg/util/ipvs/testing/fake_test.go +++ b/pkg/util/ipvs/testing/fake_test.go @@ -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"),