proxytest

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

Test framework for proxy-wasm-go-sdk

With proxytest build tag, you can test your extension with the official command:

go test -tags=proxytest ./... 

This framework emulates the expected behavior of Envoyproxy, and you can test your extensions without running Envoy. For detail, see examples/*/main_test.go.

Note that we have not covered all the functionality, and the API is very likely to change in the future.

Documentation

Index

Constants

View Source
const (
	PluginContextID uint32 = 1 // TODO: support multiple pluginContext
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EmulatorOption

type EmulatorOption struct {
	// contains filtered or unexported fields
}

func NewEmulatorOption

func NewEmulatorOption() *EmulatorOption

func (*EmulatorOption) WithPluginConfiguration

func (o *EmulatorOption) WithPluginConfiguration(data []byte) *EmulatorOption

func (*EmulatorOption) WithVMConfiguration

func (o *EmulatorOption) WithVMConfiguration(data []byte) *EmulatorOption

func (*EmulatorOption) WithVMContext added in v0.13.0

func (o *EmulatorOption) WithVMContext(context types.VMContext) *EmulatorOption

type HostEmulator

type HostEmulator interface {
	// Root
	StartVM() types.OnVMStartStatus
	StartPlugin() types.OnPluginStartStatus
	FinishVM() bool
	GetCalloutAttributesFromContext(contextID uint32) []HttpCalloutAttribute
	CallOnHttpCallResponse(contextID uint32, headers [][2]string, trailers [][2]string, body []byte)
	GetCounterMetric(name string) (uint64, error)
	GetGaugeMetric(name string) (uint64, error)
	GetHistogramMetric(name string) (uint64, error)
	GetTraceLogs() []string
	GetDebugLogs() []string
	GetInfoLogs() []string
	GetWarnLogs() []string
	GetErrorLogs() []string
	GetCriticalLogs() []string
	GetTickPeriod() uint32
	Tick()
	GetQueueSize(queueID uint32) int
	RegisterForeignFunction(name string, f func([]byte) []byte)

	// network
	InitializeConnection() (contextID uint32, action types.Action)
	CallOnUpstreamData(contextID uint32, data []byte) types.Action
	CallOnDownstreamData(contextID uint32, data []byte) types.Action
	CloseUpstreamConnection(contextID uint32)
	CloseDownstreamConnection(contextID uint32)
	CompleteConnection(contextID uint32)

	// http
	InitializeHttpContext() (contextID uint32)
	CallOnResponseHeaders(contextID uint32, headers [][2]string, endOfStream bool) types.Action
	CallOnResponseBody(contextID uint32, body []byte, endOfStream bool) types.Action
	CallOnResponseTrailers(contextID uint32, trailers [][2]string) types.Action
	CallOnRequestHeaders(contextID uint32, headers [][2]string, endOfStream bool) types.Action
	CallOnRequestTrailers(contextID uint32, trailers [][2]string) types.Action
	CallOnRequestBody(contextID uint32, body []byte, endOfStream bool) types.Action
	CompleteHttpContext(contextID uint32)
	GetCurrentHttpStreamAction(contextID uint32) types.Action
	GetCurrentRequestHeaders(contextID uint32) [][2]string
	GetCurrentRequestBody(contextID uint32) []byte
	GetSentLocalResponse(contextID uint32) *LocalHttpResponse
}

func NewHostEmulator

func NewHostEmulator(opt *EmulatorOption) (host HostEmulator, reset func())

type HttpCalloutAttribute

type HttpCalloutAttribute struct {
	CalloutID uint32
	Upstream  string
	Headers   [][2]string
	Trailers  [][2]string
	Body      []byte
}

type LocalHttpResponse

type LocalHttpResponse struct {
	StatusCode       uint32
	StatusCodeDetail string
	Data             []byte
	Headers          [][2]string
	GRPCStatus       int32
}

Jump to

Keyboard shortcuts

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