mock

package
v0.0.0-...-0000b31 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Types defines the mock config descriptor
	Types = model.ConfigDescriptor{model.MockConfig}

	// ExampleRouteRule is an example route rule
	ExampleRouteRule = &routing.RouteRule{
		Destination: &routing.IstioService{
			Name: "world",
		},
		Route: []*routing.DestinationWeight{
			{Weight: 80, Labels: map[string]string{"version": "v1"}},
			{Weight: 20, Labels: map[string]string{"version": "v2"}},
		},
	}

	// ExampleIngressRule is an example ingress rule
	ExampleIngressRule = &routing.IngressRule{
		Destination: &routing.IstioService{
			Name: "world",
		},
		Port:                   80,
		DestinationServicePort: &routing.IngressRule_DestinationPort{DestinationPort: 80},
	}

	// ExampleEgressRule is an example egress rule
	ExampleEgressRule = &routing.EgressRule{
		Destination: &routing.IstioService{
			Service: "*cnn.com",
		},
		Ports:          []*routing.EgressRule_Port{{Port: 80, Protocol: "http"}},
		UseEgressProxy: false,
	}

	// ExampleDestinationPolicy is an example destination policy
	ExampleDestinationPolicy = &routing.DestinationPolicy{
		Destination: &routing.IstioService{
			Name: "world",
		},
		LoadBalancing: &routing.LoadBalancing{
			LbPolicy: &routing.LoadBalancing_Name{Name: routing.LoadBalancing_RANDOM},
		},
	}

	// ExampleHTTPAPISpec is an example HTTPAPISpec
	ExampleHTTPAPISpec = &mccpb.HTTPAPISpec{
		Attributes: &mpb.Attributes{
			Attributes: map[string]*mpb.Attributes_AttributeValue{
				"api.service": {Value: &mpb.Attributes_AttributeValue_StringValue{"petstore"}},
			},
		},
		Patterns: []*mccpb.HTTPAPISpecPattern{{
			Attributes: &mpb.Attributes{
				Attributes: map[string]*mpb.Attributes_AttributeValue{
					"api.operation": {Value: &mpb.Attributes_AttributeValue_StringValue{"getPet"}},
				},
			},
			HttpMethod: "GET",
			Pattern: &mccpb.HTTPAPISpecPattern_UriTemplate{
				UriTemplate: "/pets/{id}",
			},
		}},
		ApiKeys: []*mccpb.APIKey{{
			Key: &mccpb.APIKey_Header{
				Header: "X-API-KEY",
			},
		}},
	}

	// ExampleQuotaSpec is an example QuotaSpec
	ExampleQuotaSpec = &mccpb.QuotaSpec{
		Rules: []*mccpb.QuotaRule{{
			Match: []*mccpb.AttributeMatch{{
				Clause: map[string]*mccpb.StringMatch{
					"api.operation": {
						MatchType: &mccpb.StringMatch_Exact{
							Exact: "getPet",
						},
					},
				},
			}},
			Quotas: []*mccpb.Quota{{
				Quota:  "fooQuota",
				Charge: 2,
			}},
		}},
	}
)
View Source
var (
	HelloService = MakeService("hello.default.svc.cluster.local", "10.1.0.0")
	WorldService = MakeService("world.default.svc.cluster.local", "10.2.0.0")
	PortHTTP     = &model.Port{
		Name:                 "http",
		Port:                 80,
		Protocol:             model.ProtocolHTTP,
		AuthenticationPolicy: meshconfig.AuthenticationPolicy_INHERIT,
	}
	Discovery = &ServiceDiscovery{
		services: map[string]*model.Service{
			HelloService.Hostname: HelloService,
			WorldService.Hostname: WorldService,
		},
		versions: 2,
	}
	HelloInstanceV0 = MakeIP(HelloService, 0)
	HelloInstanceV1 = MakeIP(HelloService, 1)
	HelloProxyV0    = proxy.Node{
		Type:      proxy.Sidecar,
		IPAddress: HelloInstanceV0,
		ID:        "v0.default",
		Domain:    "default.svc.cluster.local",
	}
	HelloProxyV1 = proxy.Node{
		Type:      proxy.Sidecar,
		IPAddress: HelloInstanceV1,
		ID:        "v1.default",
		Domain:    "default.svc.cluster.local",
	}
	Ingress = proxy.Node{
		Type:      proxy.Ingress,
		IPAddress: "10.3.3.3",
		ID:        "ingress.default",
		Domain:    "default.svc.cluster.local",
	}
	Router = proxy.Node{
		Type:      proxy.Router,
		IPAddress: "10.3.3.5",
		ID:        "router.default",
		Domain:    "default.svc.cluster.local",
	}
)

Mock values

Functions

func CheckCacheEvents

func CheckCacheEvents(store model.ConfigStore, cache model.ConfigStoreCache, namespace string, n int, t *testing.T)

CheckCacheEvents validates operational invariants of a cache

func CheckCacheFreshness

func CheckCacheFreshness(cache model.ConfigStoreCache, namespace string, t *testing.T)

CheckCacheFreshness validates operational invariants of a cache

func CheckCacheSync

func CheckCacheSync(store model.ConfigStore, cache model.ConfigStoreCache, namespace string, n int, t *testing.T)

CheckCacheSync validates operational invariants of a cache against the non-cached client.

func CheckIstioConfigTypes

func CheckIstioConfigTypes(store model.ConfigStore, namespace string, t *testing.T)

CheckIstioConfigTypes validates that an empty store can ingest Istio config objects

func CheckMapInvariant

func CheckMapInvariant(r model.ConfigStore, t *testing.T, namespace string, n int)

CheckMapInvariant validates operational invariants of an empty config registry

func Compare

func Compare(a, b model.Config) bool

Compare checks two configs ignoring revisions

func Make

func Make(namespace string, i int) model.Config

Make creates a mock config indexed by a number

func MakeIP

func MakeIP(service *model.Service, version int) string

MakeIP creates a fake IP address for a service and instance version

func MakeInstance

func MakeInstance(service *model.Service, port *model.Port, version int, az string) *model.ServiceInstance

MakeInstance creates a mock instance, version enumerates endpoints

func MakeService

func MakeService(hostname, address string) *model.Service

MakeService creates a mock service

Types

type ServiceDiscovery

type ServiceDiscovery struct {
	WantHostInstances  []*model.ServiceInstance
	ServicesError      error
	GetServiceError    error
	InstancesError     error
	HostInstancesError error
	// contains filtered or unexported fields
}

ServiceDiscovery is a mock discovery interface

func NewDiscovery

func NewDiscovery(services map[string]*model.Service, versions int) *ServiceDiscovery

NewDiscovery builds a mock ServiceDiscovery

func (*ServiceDiscovery) ClearErrors

func (sd *ServiceDiscovery) ClearErrors()

ClearErrors clear errors used for mocking failures during model.ServiceDiscovery interface methods

func (*ServiceDiscovery) GetIstioServiceAccounts

func (sd *ServiceDiscovery) GetIstioServiceAccounts(hostname string, ports []string) []string

GetIstioServiceAccounts gets the Istio service accounts for a service hostname.

func (*ServiceDiscovery) GetService

func (sd *ServiceDiscovery) GetService(hostname string) (*model.Service, error)

GetService implements discovery interface

func (*ServiceDiscovery) HostInstances

func (sd *ServiceDiscovery) HostInstances(addrs map[string]bool) ([]*model.ServiceInstance, error)

HostInstances implements discovery interface

func (*ServiceDiscovery) Instances

func (sd *ServiceDiscovery) Instances(hostname string, ports []string,
	labels model.LabelsCollection) ([]*model.ServiceInstance, error)

Instances implements discovery interface

func (*ServiceDiscovery) ManagementPorts

func (sd *ServiceDiscovery) ManagementPorts(addr string) model.PortList

ManagementPorts implements discovery interface

func (*ServiceDiscovery) Services

func (sd *ServiceDiscovery) Services() ([]*model.Service, error)

Services implements discovery interface

Jump to

Keyboard shortcuts

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