replay

package
v2.1.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package replay provides functions for replaying requests and comparing responses.

Index

Constants

View Source
const MAX_LINE_LENGTH = 50

MAX_LINE_LENGTH is chars PER expected/actual string. Can be changed no problem

Variables

This section is empty.

Functions

func AddHTTPBodyToMap

func AddHTTPBodyToMap(body string, m map[string][]string) error

func ArrayToMap

func ArrayToMap(arr []string) map[string]bool

func CheckStringExist

func CheckStringExist(s string, mp map[string][]string) ([]string, bool)

func CompareHeaders

func CompareHeaders(h1 http.Header, h2 http.Header, res *[]models.HeaderResult, noise map[string][]string) bool

func Contains

func Contains(elems []string, v string) bool

func Flatten

func Flatten(j interface{}) map[string][]string

Flatten takes a map and returns a new one where nested maps are replaced by dot-delimited keys. examples of valid jsons - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#examples

func FlattenHTTPResponse

func FlattenHTTPResponse(h http.Header, body string) (map[string][]string, error)

func InterfaceToString

func InterfaceToString(val interface{}) string

func LeftJoinNoise

func LeftJoinNoise(globalNoise config.GlobalNoise, tsNoise config.GlobalNoise) config.GlobalNoise

func MapToArray

func MapToArray(mp map[string][]string) []string

func MatchesAnyRegex

func MatchesAnyRegex(str string, regexArray []string) (bool, string)

func UnmarshallJSON

func UnmarshallJSON(s string, log *zap.Logger) (interface{}, error)

UnmarshallJSON returns unmarshalled JSON object.

Types

type DiffsPrinter

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

func NewDiffsPrinter

func NewDiffsPrinter(testCase string) DiffsPrinter

func (*DiffsPrinter) PushBodyDiff

func (d *DiffsPrinter) PushBodyDiff(exp, act string, noise map[string][]string)

func (*DiffsPrinter) PushFooterDiff

func (d *DiffsPrinter) PushFooterDiff(key string)

func (*DiffsPrinter) PushHeaderDiff

func (d *DiffsPrinter) PushHeaderDiff(exp, act, key string, noise map[string][]string)

func (*DiffsPrinter) PushStatusDiff

func (d *DiffsPrinter) PushStatusDiff(exp, act string)

func (*DiffsPrinter) Render

func (d *DiffsPrinter) Render() error

Render will display and colorize diffs side-by-side

type Instrumentation

type Instrumentation interface {
	//Setup prepares the environment for the recording
	Setup(ctx context.Context, cmd string, opts models.SetupOptions) (uint64, error)
	//Hook will load hooks and start the proxy server.
	Hook(ctx context.Context, id uint64, opts models.HookOptions) error
	MockOutgoing(ctx context.Context, id uint64, opts models.OutgoingOptions) error
	// SetMocks Allows for setting mocks between test runs for better filtering and matching
	SetMocks(ctx context.Context, id uint64, filtered []*models.Mock, unFiltered []*models.Mock) error
	// GetConsumedMocks to log the names of the mocks that were consumed during the test run of failed test cases
	GetConsumedMocks(ctx context.Context, id uint64) ([]string, error)
	// Run is blocking call and will execute until error
	Run(ctx context.Context, id uint64, opts models.RunOptions) models.AppError

	GetAppIP(ctx context.Context, id uint64) (string, error)
}

type JSONComparisonResult

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

func JSONDiffWithNoiseControl

func JSONDiffWithNoiseControl(validatedJSON ValidatedJSON, noise map[string][]string, ignoreOrdering bool) (JSONComparisonResult, error)

type MockDB

type MockDB interface {
	GetFilteredMocks(ctx context.Context, testSetID string, afterTime time.Time, beforeTime time.Time) ([]*models.Mock, error)
	GetUnFilteredMocks(ctx context.Context, testSetID string, afterTime time.Time, beforeTime time.Time) ([]*models.Mock, error)
	UpdateMocks(ctx context.Context, testSetID string, mockNames map[string]bool) error
}

type ReportDB

type ReportDB interface {
	GetAllTestRunIDs(ctx context.Context) ([]string, error)
	GetTestCaseResults(ctx context.Context, testRunID string, testSetID string) ([]models.TestResult, error)
	GetReport(ctx context.Context, testRunID string, testSetID string) (*models.TestReport, error)
	InsertTestCaseResult(ctx context.Context, testRunID string, testSetID string, result *models.TestResult) error
	InsertReport(ctx context.Context, testRunID string, testSetID string, testReport *models.TestReport) error
}

type Service

type Service interface {
	Start(ctx context.Context) error
	BootReplay(ctx context.Context) (string, uint64, context.CancelFunc, error)
	GetAllTestSetIDs(ctx context.Context) ([]string, error)
	RunTestSet(ctx context.Context, testSetID string, testRunID string, appID uint64, serveTest bool) (models.TestSetStatus, error)
	GetTestSetStatus(ctx context.Context, testRunID string, testSetID string) (models.TestSetStatus, error)
	RunApplication(ctx context.Context, appID uint64, opts models.RunOptions) models.AppError
	ProvideMocks(ctx context.Context) error
}

func NewReplayer

func NewReplayer(logger *zap.Logger, testDB TestDB, mockDB MockDB, reportDB ReportDB, telemetry Telemetry, instrumentation Instrumentation, config config.Config) Service

type Telemetry

type Telemetry interface {
	TestSetRun(success int, failure int, testSet string, runStatus string)
	TestRun(success int, failure int, testSets int, runStatus string)
	MockTestRun(utilizedMocks int)
}

type TestDB

type TestDB interface {
	GetAllTestSetIDs(ctx context.Context) ([]string, error)
	GetTestCases(ctx context.Context, testSetID string) ([]*models.TestCase, error)
}

type TestReportVerdict

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

type ValidatedJSON

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

func ValidateAndMarshalJSON

func ValidateAndMarshalJSON(log *zap.Logger, exp, act *string) (ValidatedJSON, error)

Jump to

Keyboard shortcuts

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