pacttesting

package
v2.1.7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPact

func AddPact(filename string) error

AddPact loads a pact definition from a file and ensures that stub servers are running.

func AddPactInteraction

func AddPactInteraction(provider, consumer string, interaction *dsl.Interaction) error

AddPactInteraction ensures that a stub server is running for the provided provider/consumer and returns an interaction to be configured

func EnsurePactRunning

func EnsurePactRunning(provider, consumer string) string

func IntegrationTest

func IntegrationTest(pactFilePaths []Pact, testFunc func(), retryOptions ...retry.Option) error

Runs mock services defined by the given pacts, invokes testFunc then verifies that the pacts have been invoked successfully

func PreassignPorts

func PreassignPorts(pactFilePaths []Pact)

PreassignPorts sets a random port for all future mocked instances and configures viper to point to them. This is necessary to get viper configuration before actually loading pact files. This function can be called multiple times for the same files, it will only initialise them once.

func ResetPacts

func ResetPacts()

func RunIntegrationTest added in v2.1.5

func RunIntegrationTest(t *testing.T, pactFilePaths []Pact, testFunc func(), retryOptions ...retry.Option) error

Runs mock services defined by the given pacts, invokes testFunc then verifies that the pacts have been invoked successfully

func SplitPactBulkFile

func SplitPactBulkFile(bulkFilePath string, outputDirPath string, requestFilters ...PactRequestMatchingFilter) error

SplitPactBulkFile reads bulk PACT files, splits it into smaller ones and writes output to destination directory

func StopMockServers

func StopMockServers()

func TestWithStubServices

func TestWithStubServices(pactFilePaths []Pact, testFunc func()) error

TestWithStubServices runs testFunc with stub services defined by given pacts. Does not verify that the stubs are called

func VerifyAll

func VerifyAll() error

func VerifyInteractions

func VerifyInteractions(provider, consumer string, retryOptions ...retry.Option) error

func VerifyMessageProviderRaw

func VerifyMessageProviderRaw(params PactProviderTestParams, request dsl.VerifyMessageRequest) ([]types.ProviderVerifierResponse, error)

VerifyMessageProviderRaw runs provider message verification.

func VerifyProviderMessagingPacts

func VerifyProviderMessagingPacts(params PactProviderTestParams, messageProducers dsl.MessageHandlers)

func VerifyProviderPacts

func VerifyProviderPacts(params PactProviderTestParams)

Types

type MockServer

type MockServer struct {
	Port     int
	BaseURL  string
	Consumer string
	Provider string
	Pid      int
	Running  bool `json:"-"`
}

func (*MockServer) AddInteraction

func (m *MockServer) AddInteraction(interaction interface{}) error

func (*MockServer) DeleteInteractions

func (m *MockServer) DeleteInteractions() error

func (*MockServer) Stop

func (m *MockServer) Stop() error

Stop gracefully shuts does the underlying pact-mock-service process and removes the server metadata (pid) file.

func (*MockServer) Verify

func (m *MockServer) Verify() error

type Pact

type Pact = string

type PactFile

type PactFile struct {
	Provider struct {
		Name string `json:"name"`
	} `json:"provider"`
	Consumer struct {
		Name string `json:"name"`
	} `json:"consumer"`
	Interactions []struct {
		Description    string      `json:"description"`
		ProviderStates interface{} `json:"providerStates"`
		Request        interface{} `json:"request"`
		Response       interface{} `json:"response"`
	} `json:"interactions"`
	Metadata interface{} `json:"metadata"`
}

PactFile describes expectations between provider and consumer

func NewPactFile

func NewPactFile(data []byte) (*PactFile, error)

NewPactFile create new PACT file representation

func (*PactFile) Split

func (f *PactFile) Split() *[]*PactFile

Split divides bulk file with many interactions to single-interaction PACT files. It's required as a workaround to make bigger PACT test runs working.

type PactProviderTestParams

type PactProviderTestParams struct {
	Pacts                 string
	AuthToken             string
	BaseURL               string
	ProviderStateSetupURL string
	Testing               *testing.T
}

type PactRequestMatchingFilter

type PactRequestMatchingFilter = func(map[string]interface{})

Jump to

Keyboard shortcuts

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