k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/proxy/ipvs/testing/fake_test.go (about) 1 //go:build linux 2 // +build linux 3 4 /* 5 Copyright 2017 The Kubernetes Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 */ 19 20 package testing 21 22 import ( 23 "testing" 24 25 "k8s.io/apimachinery/pkg/util/sets" 26 "k8s.io/kubernetes/pkg/proxy/ipvs" 27 ) 28 29 // (I am unsure if this test has any value since it only tests the fake implementation) 30 func TestSetGetLocalAddresses(t *testing.T) { 31 fake := NewFakeNetlinkHandle(false) 32 _ = ipvs.NetLinkHandle(fake) // Ensure that the interface is honored 33 fake.SetLocalAddresses("eth0", "1.2.3.4") 34 var expected, addr sets.Set[string] 35 expected = sets.New("1.2.3.4") 36 addr, _ = fake.GetLocalAddresses("eth0") 37 if !addr.Equal(expected) { 38 t.Errorf("Unexpected mismatch, expected: %v, got: %v", expected, addr) 39 } 40 addr, _ = fake.GetAllLocalAddresses() 41 if !addr.Equal(expected) { 42 t.Errorf("Unexpected mismatch, expected: %v, got: %v", expected, addr) 43 } 44 fake.SetLocalAddresses("lo", "127.0.0.1") 45 expected = nil 46 addr, _ = fake.GetLocalAddresses("lo") 47 if !addr.Equal(expected) { 48 t.Errorf("Unexpected mismatch, expected: %v, got: %v", expected, addr) 49 } 50 fake.SetLocalAddresses("kube-ipvs0", "1.2.3.4", "4.3.2.1") 51 addr, _ = fake.GetAllLocalAddresses() 52 expected = sets.New("1.2.3.4", "4.3.2.1") 53 if !addr.Equal(expected) { 54 t.Errorf("Unexpected mismatch, expected: %v, got: %v", expected, addr) 55 } 56 addr, _ = fake.GetAllLocalAddressesExcept("kube-ipvs0") 57 expected = sets.New("1.2.3.4") 58 if !addr.Equal(expected) { 59 t.Errorf("Unexpected mismatch, expected: %v, got: %v", expected, addr) 60 } 61 }