native

package
v2.0.0-beta.8 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package native contains the c bindings into the Pact Reference types.

Index

Constants

View Source
const (
	INTERACTION_PART_REQUEST interactionType = iota
	INTERACTION_PART_RESPONSE
)
View Source
const (
	RESULT_OK interactionType = iota
	RESULT_FAILED
)
View Source
const (
	SPECIFICATION_VERSION_UNKNOWN specificationVersion = iota
	SPECIFICATION_VERSION_V1
	SPECIFICATION_VERSION_V1_1
	SPECIFICATION_VERSION_V2
	SPECIFICATION_VERSION_V3
	SPECIFICATION_VERSION_V4
)
View Source
const (
	LOG_LEVEL_OFF logLevel = iota
	LOG_LEVEL_ERROR
	LOG_LEVEL_WARN
	LOG_LEVEL_INFO
	LOG_LEVEL_DEBUG
	LOG_LEVEL_TRACE
)

Variables

View Source
var (
	// ErrHandleNotFound indicates the underlying handle was not found, and a logic error in the framework
	ErrHandleNotFound = fmt.Errorf("unable to find the native interface handle (this indicates a defect in the framework)")

	// ErrMockServerPanic indicates a panic ocurred when invoking the remote Mock Server.
	ErrMockServerPanic = fmt.Errorf("a general panic occured when starting/invoking mock service (this indicates a defect in the framework)")

	// ErrUnableToWritePactFile indicates an error when writing the pact file to disk.
	ErrUnableToWritePactFile = fmt.Errorf("unable to write to file")

	// ErrMockServerNotfound indicates the Mock Server could not be found.
	ErrMockServerNotfound = fmt.Errorf("unable to find mock server with the given port")

	// ErrInvalidMockServerConfig indicates an issue configuring the mock server
	ErrInvalidMockServerConfig = fmt.Errorf("configuration for the mock server was invalid and an unknown error occurred (this is most likely a defect in the framework)")

	// ErrInvalidPact indicates the pact file provided to the mock server was not a valid pact file
	ErrInvalidPact = fmt.Errorf("pact given to mock server is invalid")

	// ErrMockServerUnableToStart means the mock server could not be started in the rust library
	ErrMockServerUnableToStart = fmt.Errorf("unable to start the mock server")

	// ErrInvalidAddress means the address provided to the mock server was invalid and could not be understood
	ErrInvalidAddress = fmt.Errorf("invalid address provided to the mock server")

	// ErrMockServerTLSConfiguration indicates a TLS mock server could not be started
	// and is likely a framework level problem
	ErrMockServerTLSConfiguration = fmt.Errorf("a tls mock server could not be started (this is likely a defect in the framework)")

	// ErrNoInteractions indicates no Interactions have been registered to a mock server, and cannot be started/stopped until at least one is added
	ErrNoInteractions = fmt.Errorf("no interactions have been registered for the mock server")
)

Errors

View Source
var (
	ErrCantSetLogger      = fmt.Errorf("can't set logger (applying the logger failed, perhaps because one is applied already).")
	ErrNoLogger           = fmt.Errorf("no logger has been initialized (call `logger_init` before any other log function).")
	ErrSpecifierNotUtf8   = fmt.Errorf("The sink specifier was not UTF-8 encoded.")
	ErrUnknownSinkType    = fmt.Errorf(`the sink type specified is not a known type (known types: "buffer", "stdout", "stderr", or "file /some/path").`)
	ErrMissingFilePath    = fmt.Errorf("no file path was specified in a file-type sink specification.")
	ErrCantOpenSinkToFile = fmt.Errorf("opening a sink to the specified file path failed (check permissions).")
	ErrCantConstructSink  = fmt.Errorf("can't construct the log sink")
)

Log Errors

View Source
var (
	// ErrVerifierPanic indicates a panic ocurred when invoking the verifier.
	ErrVerifierPanic = fmt.Errorf("a general panic occured when starting/invoking verifier (this indicates a defect in the framework)")

	// ErrInvalidVerifierConfig indicates an issue configuring the verifier
	ErrInvalidVerifierConfig = fmt.Errorf("configuration for the verifier was invalid and an unknown error occurred (this is most likely a defect in the framework)")

	//ErrVerifierFailed is the standard error if a verification failed (e.g. beacause the pact verification was not successful)
	ErrVerifierFailed = fmt.Errorf("the verifier failed to successfully verify the pacts, this indicates an issue with the provider API")
)

Functions

func GetTLSConfig

func GetTLSConfig() *tls.Config

GetTLSConfig returns a tls.Config compatible with the TLS mock server

func Init

func Init()

Init initialises the library

func Version

func Version() string

Version returns the current semver FFI interface version

Types

type Interaction

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

Interaction is a Go representation of the InteractionHandle struct

func (*Interaction) Given

func (i *Interaction) Given(state string) *Interaction

func (*Interaction) GivenWithParameter

func (i *Interaction) GivenWithParameter(state string, params map[string]interface{}) *Interaction

func (*Interaction) UponReceiving

func (i *Interaction) UponReceiving(description string) *Interaction

func (*Interaction) WithBinaryRequestBody

func (i *Interaction) WithBinaryRequestBody(body []byte) *Interaction

func (*Interaction) WithBinaryResponseBody

func (i *Interaction) WithBinaryResponseBody(body []byte) *Interaction

func (*Interaction) WithJSONRequestBody

func (i *Interaction) WithJSONRequestBody(body interface{}) *Interaction

func (*Interaction) WithJSONResponseBody

func (i *Interaction) WithJSONResponseBody(body interface{}) *Interaction

func (*Interaction) WithQuery

func (i *Interaction) WithQuery(valueOrMatcher map[string][]interface{}) *Interaction

func (*Interaction) WithRequest

func (i *Interaction) WithRequest(method string, pathOrMatcher interface{}) *Interaction

func (*Interaction) WithRequestBody

func (i *Interaction) WithRequestBody(contentType string, body []byte) *Interaction

func (*Interaction) WithRequestHeaders

func (i *Interaction) WithRequestHeaders(valueOrMatcher map[string][]interface{}) *Interaction

func (*Interaction) WithRequestMultipartFile

func (i *Interaction) WithRequestMultipartFile(contentType string, filename string, mimePartName string) *Interaction

func (*Interaction) WithResponseBody

func (i *Interaction) WithResponseBody(contentType string, body []byte) *Interaction

func (*Interaction) WithResponseHeaders

func (i *Interaction) WithResponseHeaders(valueOrMatcher map[string][]interface{}) *Interaction

func (*Interaction) WithResponseMultipartFile

func (i *Interaction) WithResponseMultipartFile(contentType string, filename string, mimePartName string) *Interaction

func (*Interaction) WithStatus

func (i *Interaction) WithStatus(status int) *Interaction

Set the expected HTTTP response status

type Message

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

func (*Message) ExpectsToReceive

func (i *Message) ExpectsToReceive(description string) *Message

func (*Message) Given

func (i *Message) Given(state string) *Message

func (*Message) GivenWithParameter

func (i *Message) GivenWithParameter(state string, params map[string]interface{}) *Message

func (*Message) ReifyMessage

func (i *Message) ReifyMessage() string

func (*Message) WithBinaryContents

func (i *Message) WithBinaryContents(body []byte) *Message

func (*Message) WithContents

func (i *Message) WithContents(contentType string, body []byte) *Message

func (*Message) WithJSONContents

func (i *Message) WithJSONContents(body interface{}) *Message

func (*Message) WithMetadata

func (i *Message) WithMetadata(valueOrMatcher map[string]string) *Message

type MessagePact

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

type MessageServer

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

MessageServer is the public interface for managing the message based interface

func NewMessageServer

func NewMessageServer(consumer string, provider string) *MessageServer

NewMessage initialises a new message for the current contract

func (*MessageServer) NewMessage

func (m *MessageServer) NewMessage() *Message

NewMessage initialises a new message for the current contract

func (*MessageServer) WithMetadata

func (m *MessageServer) WithMetadata(namespace, k, v string) *MessageServer

Sets the additional metadata on the Pact file. Common uses are to add the client library details such as the name and version

func (*MessageServer) WritePactFile

func (m *MessageServer) WritePactFile(dir string, overwrite bool) error

WritePactFile writes the Pact to file.

type MismatchDetail

type MismatchDetail struct {
	Actual   string
	Expected string
	Key      string
	Mismatch string
	Type     string
}

MismatchDetail contains the specific assertions that failed during the verification

type MismatchedRequest

type MismatchedRequest struct {
	Request
	Mismatches []MismatchDetail
	Type       string
}

MismatchedRequest contains details of any request mismatches during pact verification

type MockServer

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

MockServer is the public interface for managing the HTTP mock server

func NewHTTPMockServer

func NewHTTPMockServer(consumer string, provider string) *MockServer

NewMockServer creates a new mock server for a given consumer/provider

func (*MockServer) CleanupMockServer

func (m *MockServer) CleanupMockServer(port int) bool

CleanupMockServer frees the memory from the previous mock server.

func (*MockServer) CreateMockServer

func (m *MockServer) CreateMockServer(pact string, address string, tls bool) (int, error)

CreateMockServer creates a new Mock Server from a given Pact file. Returns the port number it started on or an error if failed

func (*MockServer) MockServerMismatchedRequests

func (m *MockServer) MockServerMismatchedRequests(port int) []MismatchedRequest

MockServerMismatchedRequests returns a JSON object containing any mismatches from the last set of interactions.

func (*MockServer) NewInteraction

func (m *MockServer) NewInteraction(description string) *Interaction

NewInteraction initialises a new interaction for the current contract

func (*MockServer) Start

func (m *MockServer) Start(address string, tls bool) (int, error)

Start starts up the mock HTTP server on the given address:port and TLS config https://docs.rs/pact_mock_server_ffi/0.0.7/pact_mock_server_ffi/fn.create_mock_server_for_pact.html

func (*MockServer) Verify

func (m *MockServer) Verify(port int, dir string) (bool, []MismatchedRequest)

Verify verifies that all interactions were successful. If not, returns a slice of Mismatch-es. Does not write the pact or cleanup server.

func (*MockServer) Version

func (m *MockServer) Version() string

Version returns the current semver FFI interface version

func (*MockServer) WithMetadata

func (m *MockServer) WithMetadata(namespace, k, v string) *MockServer

Sets the additional metadata on the Pact file. Common uses are to add the client library details such as the name and version

func (*MockServer) WithSpecificationVersion

func (m *MockServer) WithSpecificationVersion(version specificationVersion)

func (*MockServer) WritePactFile

func (m *MockServer) WritePactFile(port int, dir string) error

WritePactFile writes the Pact to file.

type Pact

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

Pact is a Go representation of the PactHandle struct

type Request

type Request struct {
	Method  string            `json:"method"`
	Path    string            `json:"path"`
	Query   string            `json:"query,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
	Body    interface{}       `json:"body,omitempty"`
}

Request is the sub-struct of Mismatch

type Verifier

type Verifier struct{}

func (*Verifier) Verify

func (v *Verifier) Verify(args []string) error

func (*Verifier) Version

func (v *Verifier) Version() string

Version returns the current semver FFI interface version

Jump to

Keyboard shortcuts

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