1
0
forked from extern/smegmesh
smegmesh/pkg/conn/stub.go
Tim Beatham 2d5df25b1d main
- If deadline exceeded error remove connection from
connection manager
2023-12-29 01:29:11 +00:00

57 lines
1.1 KiB
Go

package conn
import (
"crypto/tls"
"google.golang.org/grpc"
)
type ConnectionManagerStub struct {
Endpoints map[string]PeerConnection
}
func (s *ConnectionManagerStub) AddConnection(endPoint string) (PeerConnection, error) {
mock := &PeerConnectionMock{}
s.Endpoints[endPoint] = mock
return mock, nil
}
func (s *ConnectionManagerStub) RemoveConnection(endPoint string) error {
delete(s.Endpoints, endPoint)
return nil
}
func (s *ConnectionManagerStub) GetConnection(endPoint string) (PeerConnection, error) {
endpoint, ok := s.Endpoints[endPoint]
if !ok {
return s.AddConnection(endPoint)
}
return endpoint, nil
}
func (s *ConnectionManagerStub) HasConnection(endPoint string) bool {
_, ok := s.Endpoints[endPoint]
return ok
}
func (s *ConnectionManagerStub) Close() error {
return nil
}
type PeerConnectionMock struct {
}
func (c *PeerConnectionMock) Close() error {
return nil
}
func (c *PeerConnectionMock) GetClient() (*grpc.ClientConn, error) {
return &grpc.ClientConn{}, nil
}
var MockFactory PeerConnectionFactory = func(clientConfig *tls.Config, server string) (PeerConnection, error) {
return &PeerConnectionMock{}, nil
}