testutils

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoopDNSGetter = FakeFQDNCache{
	OnGetNamesOf: func(sourceEpID uint64, ip net.IP) (fqdns []string) {
		return nil
	},
}

NoopDNSGetter always returns an empty response.

View Source
var NoopEndpointGetter = FakeEndpointGetter{
	OnGetEndpointInfo: func(ip net.IP) (endpoint v1.EndpointInfo, ok bool) {
		return nil, false
	},
}

NoopEndpointGetter always returns an empty response.

View Source
var NoopIPGetter = FakeIPGetter{
	OnGetIPIdentity: func(ip net.IP) (id ipcache.IPIdentity, ok bool) {
		return ipcache.IPIdentity{}, false
	},
}

NoopIPGetter always returns an empty response.

View Source
var NoopIdentityGetter = FakeIdentityGetter{
	OnGetIdentity: func(securityIdentity uint64) (*models.Identity, error) {
		return &models.Identity{}, nil
	},
}

NoopIdentityGetter always returns an empty response.

View Source
var NoopServiceGetter = FakeServiceGetter{
	OnGetServiceByAddr: func(ip net.IP, port uint16) (service pb.Service, ok bool) {
		return pb.Service{}, false
	},
}

NoopServiceGetter always returns an empty response.

Functions

func CreateL3L4Payload

func CreateL3L4Payload(message interface{}, layers ...gopacket.SerializableLayer) ([]byte, error)

CreateL3L4Payload assembles a L3/L4 payload for testing purposes

func MustCreateL3L4Payload

func MustCreateL3L4Payload(message interface{}, layers ...gopacket.SerializableLayer) []byte

MustCreateL3L4Payload wraps CreateL3L4Payload, but panics on error

Types

type FakeCiliumClient

type FakeCiliumClient struct {
	FakeEndpointList    func() ([]*models.Endpoint, error)
	FakeGetEndpoint     func(uint64) (*models.Endpoint, error)
	FakeGetIdentity     func(uint64) (*models.Identity, error)
	FakeGetFqdnCache    func() ([]*models.DNSLookup, error)
	FakeGetIPCache      func() ([]*models.IPListEntry, error)
	FakeGetServiceCache func() ([]*models.Service, error)
}

FakeCiliumClient implements CliliumClient interface for unit testing.

func (*FakeCiliumClient) EndpointList

func (c *FakeCiliumClient) EndpointList() ([]*models.Endpoint, error)

EndpointList calls FakeEndpointList.

func (*FakeCiliumClient) GetEndpoint

func (c *FakeCiliumClient) GetEndpoint(id uint64) (*models.Endpoint, error)

GetEndpoint calls FakeGetEndpoint.

func (*FakeCiliumClient) GetFqdnCache

func (c *FakeCiliumClient) GetFqdnCache() ([]*models.DNSLookup, error)

GetFqdnCache calls FakeGetFqdnCache.

func (*FakeCiliumClient) GetIPCache

func (c *FakeCiliumClient) GetIPCache() ([]*models.IPListEntry, error)

GetIPCache calls FakeGetIPCache.

func (*FakeCiliumClient) GetIdentity

func (c *FakeCiliumClient) GetIdentity(id uint64) (*models.Identity, error)

GetIdentity calls FakeGetIdentity.

func (*FakeCiliumClient) GetServiceCache

func (c *FakeCiliumClient) GetServiceCache() ([]*models.Service, error)

GetServiceCache calls FakeGetServiceCache.

type FakeEndpointGetter

type FakeEndpointGetter struct {
	OnGetEndpointInfo func(ip net.IP) (endpoint v1.EndpointInfo, ok bool)
}

FakeEndpointGetter is used for unit tests that needs EndpointGetter.

func (*FakeEndpointGetter) GetEndpointInfo

func (f *FakeEndpointGetter) GetEndpointInfo(ip net.IP) (endpoint v1.EndpointInfo, ok bool)

GetEndpointInfo implements EndpointGetter.GetEndpointInfo.

type FakeEndpointsHandler

type FakeEndpointsHandler struct {
	FakeSyncEndpoints            func([]*v1.Endpoint)
	FakeUpdateEndpoint           func(*v1.Endpoint)
	FakeDeleteEndpoint           func(*v1.Endpoint)
	FakeFindEPs                  func(epID uint64, ns, pod string) []v1.Endpoint
	FakeGetEndpoint              func(ip net.IP) (endpoint *v1.Endpoint, ok bool)
	FakeGetEndpointByContainerID func(id string) (endpoint *v1.Endpoint, ok bool)
	FakeGetEndpointByPodName     func(namespace string, name string) (*v1.Endpoint, bool)
}

FakeEndpointsHandler implements EndpointsHandler interface for unit testing.

func (*FakeEndpointsHandler) DeleteEndpoint

func (f *FakeEndpointsHandler) DeleteEndpoint(ep *v1.Endpoint)

DeleteEndpoint calls FakeDeleteEndpoint.

func (*FakeEndpointsHandler) FindEPs

func (f *FakeEndpointsHandler) FindEPs(epID uint64, ns, pod string) []v1.Endpoint

FindEPs calls FakeFindEPs.

func (*FakeEndpointsHandler) GetEndpoint

func (f *FakeEndpointsHandler) GetEndpoint(ip net.IP) (ep *v1.Endpoint, ok bool)

GetEndpoint calls FakeGetEndpoint.

func (*FakeEndpointsHandler) GetEndpointByContainerID

func (f *FakeEndpointsHandler) GetEndpointByContainerID(id string) (ep *v1.Endpoint, ok bool)

GetEndpointByContainerID calls FakeGetEndpointByContainerID.

func (*FakeEndpointsHandler) GetEndpointByPodName

func (f *FakeEndpointsHandler) GetEndpointByPodName(namespace string, name string) (ep *v1.Endpoint, ok bool)

GetEndpointByPodName calls FakeGetEndpointByPodName.

func (*FakeEndpointsHandler) SyncEndpoints

func (f *FakeEndpointsHandler) SyncEndpoints(eps []*v1.Endpoint)

SyncEndpoints calls FakeSyncEndpoints.

func (*FakeEndpointsHandler) UpdateEndpoint

func (f *FakeEndpointsHandler) UpdateEndpoint(ep *v1.Endpoint)

UpdateEndpoint calls FakeUpdateEndpoint.

type FakeFQDNCache

type FakeFQDNCache struct {
	OnInitializeFrom func(entries []*models.DNSLookup)
	OnAddDNSLookup   func(epID uint64, lookupTime time.Time, domainName string, ips []net.IP, ttl uint32)
	OnGetNamesOf     func(epID uint64, ip net.IP) []string
}

FakeFQDNCache is used for unit tests that needs FQDNCache and/or DNSGetter.

func (*FakeFQDNCache) AddDNSLookup

func (f *FakeFQDNCache) AddDNSLookup(epID uint64, lookupTime time.Time, domainName string, ips []net.IP, ttl uint32)

AddDNSLookup implements FQDNCache.AddDNSLookup.

func (*FakeFQDNCache) GetNamesOf

func (f *FakeFQDNCache) GetNamesOf(epID uint64, ip net.IP) []string

GetNamesOf implements FQDNCache.GetNameOf.

func (*FakeFQDNCache) InitializeFrom

func (f *FakeFQDNCache) InitializeFrom(entries []*models.DNSLookup)

InitializeFrom implements FQDNCache.InitializeFrom.

type FakeFlow

type FakeFlow struct {
	Time               *types.Timestamp
	Verdict            pb.Verdict
	DropReason         uint32
	Ethernet           *pb.Ethernet
	IP                 *pb.IP
	L4                 *pb.Layer4
	Source             *pb.Endpoint
	Destination        *pb.Endpoint
	Type               pb.FlowType
	NodeName           string
	SourceNames        []string
	DestinationNames   []string
	L7                 *pb.Layer7
	Reply              bool
	EventType          *pb.CiliumEventType
	SourceService      *pb.Service
	DestinationService *pb.Service
}

FakeFlow implements v1.Flow for unit tests. All interface methods return values exposed in the fields.

func (*FakeFlow) GetDestination

func (f *FakeFlow) GetDestination() *pb.Endpoint

GetDestination implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetDestinationNames

func (f *FakeFlow) GetDestinationNames() []string

GetDestinationNames implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetDestinationService

func (f *FakeFlow) GetDestinationService() *pb.Service

GetDestinationService implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetDropReason

func (f *FakeFlow) GetDropReason() uint32

GetDropReason implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetEthernet

func (f *FakeFlow) GetEthernet() *pb.Ethernet

GetEthernet implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetEventType

func (f *FakeFlow) GetEventType() *pb.CiliumEventType

GetEventType implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetIP

func (f *FakeFlow) GetIP() *pb.IP

GetIP implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetL4

func (f *FakeFlow) GetL4() *pb.Layer4

GetL4 implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetL7

func (f *FakeFlow) GetL7() *pb.Layer7

GetL7 implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetNodeName

func (f *FakeFlow) GetNodeName() string

GetNodeName implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetReply

func (f *FakeFlow) GetReply() bool

GetReply implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetSource

func (f *FakeFlow) GetSource() *pb.Endpoint

GetSource implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetSourceNames

func (f *FakeFlow) GetSourceNames() []string

GetSourceNames implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetSourceService

func (f *FakeFlow) GetSourceService() *pb.Service

GetSourceService implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetSummary

func (f *FakeFlow) GetSummary() string

GetSummary implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetTime

func (f *FakeFlow) GetTime() *types.Timestamp

GetTime implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetType

func (f *FakeFlow) GetType() pb.FlowType

GetType implements v1.Flow for the FakeFlow.

func (*FakeFlow) GetVerdict

func (f *FakeFlow) GetVerdict() pb.Verdict

GetVerdict implements v1.Flow for the FakeFlow.

func (*FakeFlow) ProtoMessage

func (f *FakeFlow) ProtoMessage()

ProtoMessage implements pb.Message for the FakeFlow.

func (*FakeFlow) Reset

func (f *FakeFlow) Reset()

Reset implements pb.Message for the FakeFlow.

func (*FakeFlow) String

func (f *FakeFlow) String() string

String implements pb.Message for the FakeFlow.

type FakeIPGetter

type FakeIPGetter struct {
	OnGetIPIdentity func(ip net.IP) (id ipcache.IPIdentity, ok bool)
}

FakeIPGetter is used for unit tests that needs IPGetter.

func (*FakeIPGetter) GetIPIdentity

func (f *FakeIPGetter) GetIPIdentity(ip net.IP) (id ipcache.IPIdentity, ok bool)

GetIPIdentity implements FakeIPGetter.GetIPIdentity.

type FakeIdentityGetter

type FakeIdentityGetter struct {
	OnGetIdentity func(securityIdentity uint64) (*models.Identity, error)
}

FakeIdentityGetter is used for unit tests that need IdentityGetter.

func (*FakeIdentityGetter) GetIdentity

func (f *FakeIdentityGetter) GetIdentity(securityIdentity uint64) (*models.Identity, error)

GetIdentity implements IdentityGetter.GetIPIdentity.

type FakeServiceGetter

type FakeServiceGetter struct {
	OnGetServiceByAddr func(ip net.IP, port uint16) (service pb.Service, ok bool)
}

FakeServiceGetter is used for unit tests that need ServiceGetter.

func (*FakeServiceGetter) GetServiceByAddr

func (f *FakeServiceGetter) GetServiceByAddr(ip net.IP, port uint16) (service pb.Service, ok bool)

GetServiceByAddr implements FakeServiceGetter.GetServiceByAddr.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL