github.com/cilium/cilium@v1.16.2/pkg/service/healthserver/healthserver_mock.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package healthserver 5 6 // MockHealthHTTPServerFactory mocks the healthHTTPServerFactory interface 7 type MockHealthHTTPServerFactory struct { 8 serversByPort map[uint16]*mockHealthServer 9 } 10 11 // NewMockHealthHTTPServerFactory creates a new health server factory for testing 12 func NewMockHealthHTTPServerFactory() *MockHealthHTTPServerFactory { 13 return &MockHealthHTTPServerFactory{ 14 serversByPort: map[uint16]*mockHealthServer{}, 15 } 16 } 17 18 // ServiceByPort returns the service for a given health check node port 19 func (m *MockHealthHTTPServerFactory) ServiceByPort(port uint16) *Service { 20 if srv, ok := m.serversByPort[port]; ok { 21 return srv.svc 22 } 23 return nil 24 } 25 26 func (m *MockHealthHTTPServerFactory) newHTTPHealthServer(port uint16, svc *Service) healthHTTPServer { 27 m.serversByPort[port] = &mockHealthServer{ 28 port: port, 29 svc: svc, 30 factory: m, 31 } 32 33 return m.serversByPort[port] 34 } 35 36 type mockHealthServer struct { 37 port uint16 38 svc *Service 39 factory *MockHealthHTTPServerFactory 40 } 41 42 func (m *mockHealthServer) updateService(svc *Service) { 43 m.svc = svc 44 } 45 46 func (m *mockHealthServer) shutdown() { 47 delete(m.factory.serversByPort, m.port) 48 }