istio: istio.io/istio/mixer/pkg/mockapi Index | Files

package mockapi

import "istio.io/istio/mixer/pkg/mockapi"

Package mockapi supplies a fake Mixer server for use in testing. It should NOT be used outside of testing contexts.

Index

Package Files

handler.go server.go

Variables

var DefaultAmount = int64(1)

DefaultAmount is the default quota amount to use in testing (1).

var DefaultValidDuration = 5 * time.Second

DefaultValidDuration is the default duration to return for quota allocs in testing (1s).

var DefaultValidUseCount = int32(10000)

DefaultValidUseCount is the default number of valid uses to return for quota allocs for testing (1).

func ListenerAndPort Uses

func ListenerAndPort() (net.Listener, int, error)

ListenerAndPort starts a listener on an available port and returns both the listener and the port on which it is listening.

func NewMixerServer Uses

func NewMixerServer(impl mixerpb.MixerServer) *grpc.Server

NewMixerServer creates a new grpc.Server with the supplied implementation of the Mixer API.

type AttributesHandler Uses

type AttributesHandler interface {
    // Check will be called once per Mixer API Check() request.
    Check(attribute.Bag) mixerpb.CheckResponse_PreconditionResult

    // Quota will be called once per quota (with params) received in a Check()
    // request.
    Quota(attribute.Bag, QuotaArgs) (QuotaResponse, rpc.Status)

    // Report will be called once per set of attributes received in a Report()
    // request.
    Report(attribute.Bag) rpc.Status
}

AttributesHandler provides an interface for building custom testing behavior. AttributesHandlers are used by a test.AttributesServer to pass attribute bags to testing code for validation of proper transport using the Mixer API.

type AttributesServer Uses

type AttributesServer struct {
    // GlobalDict controls the known global dictionary for attribute processing.
    GlobalDict map[string]int32

    // Handler is what the server will call to simulate passing attribute bags
    // and method args within the Mixer server. It allows tests to gain access
    // to the attribute handling pipeline within Mixer and to set the response
    // details.
    Handler AttributesHandler

    // GenerateGRPCError instructs the server whether or not to fail-fast with
    // an error that will manifest as a GRPC error.
    GenerateGRPCError bool
    // contains filtered or unexported fields
}

AttributesServer implements the Mixer API to send mutable attributes bags to a channel upon API requests. This can be used for tests that want to exercise the Mixer API and validate server handling of supplied attributes.

func NewAttributesServer Uses

func NewAttributesServer(handler AttributesHandler, checkDict bool) *AttributesServer

NewAttributesServer creates an AttributesServer. All channels are set to default length.

func (*AttributesServer) Check Uses

func (a *AttributesServer) Check(ctx context.Context, req *mixerpb.CheckRequest) (*mixerpb.CheckResponse, error)

Check sends a copy of the protocol buffers attributes wrapper for the preconditions check as well as for each quotas check to the CheckAttributes channel. It also builds a CheckResponse based on server fields. All channel sends timeout to prevent problematic tests from blocking indefinitely.

func (*AttributesServer) Report Uses

func (a *AttributesServer) Report(ctx context.Context, req *mixerpb.ReportRequest) (*mixerpb.ReportResponse, error)

Report iterates through the supplied attributes sets, applying the deltas appropriately, and sending the generated bags to the channel.

func (*AttributesServer) SetCheckMetadata Uses

func (a *AttributesServer) SetCheckMetadata(checkMetadata func(*mixerpb.Attributes) error)

SetCheckMetadata enables gRPC metadata checking.

type ChannelsHandler Uses

type ChannelsHandler struct {
    AttributesHandler

    // QuotaResponse controls the response returned as part of Quota() calls.
    QuotaResponse QuotaResponse

    // ReturnStatus controls the rpc.Status returned for Check(), Quota(), and
    // Report() calls.
    ReturnStatus rpc.Status

    // CheckAttributes is the channel on which the attribute bag generated by
    // the server for Check() requests is sent.
    CheckAttributes chan attribute.Bag

    // QuotaDispatches is the channel on which the quota information generated by
    // the server for Check() requests is sent.
    QuotaDispatches chan QuotaDispatchInfo

    // ReportAttributes is the channel on which the attribute bag generated by
    // the server for Report() requests is sent.
    ReportAttributes chan attribute.Bag
}

ChannelsHandler sends received attribute.Bags (and other) information on the configured channels (with a timeout).

func NewChannelsHandler Uses

func NewChannelsHandler() *ChannelsHandler

NewChannelsHandler creates a ChannelsHandler with channels of default length and default values for ReturnStatuses and QuotaResponses.

func (*ChannelsHandler) Check Uses

func (c *ChannelsHandler) Check(req attribute.Bag) mixerpb.CheckResponse_PreconditionResult

Check implements AttributesHandler interface.

func (*ChannelsHandler) Quota Uses

func (c *ChannelsHandler) Quota(req attribute.Bag, qma QuotaArgs) (QuotaResponse, rpc.Status)

Quota implements AttributesHandler interface.

func (*ChannelsHandler) Report Uses

func (c *ChannelsHandler) Report(req attribute.Bag) rpc.Status

Report implements AttributesHandler interface.

type QuotaArgs Uses

type QuotaArgs struct {
    // Unique ID for Quota operation.
    DeduplicationID string

    // The quota to allocate from.
    Quota string

    // The amount of quota to allocate.
    Amount int64

    // If true, allows a response to return less quota than requested. When
    // false, the exact requested amount is returned or 0 if not enough quota
    // was available.
    BestEffort bool
}

QuotaArgs mirrors aspect.QuotaArgs. It allows tests to understand how their inputs map into quota calls within Mixer to validate the proper requests are being generated. It is NOT a contract for how a real Mixer would generate or dispatch Quota calls.

type QuotaDispatchInfo Uses

type QuotaDispatchInfo struct {
    Attributes attribute.Bag
    MethodArgs QuotaArgs
}

QuotaDispatchInfo contains both the attribute bag generated by the server for Quota dispatch, as well as the corresponding method arguments.

type QuotaResponse Uses

type QuotaResponse struct {
    // The amount of time until which the returned quota expires, this is 0 for non-expiring quotas.
    Expiration time.Duration

    // The total amount of quota returned, may be less than requested.
    Amount int64

    // Referenced attributes for client
    Referenced *mixerpb.ReferencedAttributes
}

QuotaResponse provides information on the result of a Quota operation. It allows testing to target precise quota responses.

Package mockapi imports 15 packages (graph) and is imported by 1 packages. Updated 2019-08-06. Refresh now. Tools for package owners.