Merge pull request #53519 from m1093782566/more-fakes

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

implement fakeIPVS update virtual server

**What this PR does / why we need it**:

* Implement UpdateVirtualServer() for FakeIPVS because ipvs/proxier needs it.

* Add UTs - Since there are some real logics in fakeIPVS interface, it's important to add some UTs which can help avoiding some mistakes.

**Which issue this PR fixes**: fixes #53518

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-10-06 00:27:28 -07:00 committed by GitHub
commit 4f00d3a67d
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"),