Documentation ¶
Overview ¶
Package replay provides functions for replaying requests and comparing responses.
Index ¶
- Constants
- func AbsMatch(tcs1, tcs2 *models.TestCase, noiseConfig map[string]map[string][]string, ...) (bool, bool, bool, *models.AbsResult)
- func AddHTTPBodyToMap(body string, m map[string][]string) error
- func ArrayToMap(arr []string) map[string]bool
- func CheckStringExist(s string, mp map[string][]string) ([]string, bool)
- func CompareCurl(curl1, curl2 string, logger *zap.Logger) bool
- func CompareHTTPReq(tcs1, tcs2 *models.TestCase, _ models.GlobalNoise, ignoreOrdering bool, ...) (bool, models.ReqCompare)
- func CompareHTTPResp(tcs1, tcs2 *models.TestCase, noiseConfig models.GlobalNoise, ...) (bool, models.RespCompare)
- func CompareHeaders(h1 http.Header, h2 http.Header, res *[]models.HeaderResult, ...) bool
- func CompareNoise(noise1, noise2 map[string][]string) bool
- func CompareURLParams(urlParams1, urlParams2 map[string]string, ...) bool
- func Contains(elems []string, v string) bool
- func Flatten(j interface{}) map[string][]string
- func FlattenHTTPResponse(h http.Header, body string) (map[string][]string, error)
- func InterfaceToString(val interface{}) string
- func LeftJoinNoise(globalNoise config.GlobalNoise, tsNoise config.GlobalNoise) config.GlobalNoise
- func MapToArray(mp map[string][]string) []string
- func MatchesAnyRegex(str string, regexArray []string) (bool, string)
- func ReplaceBaseURL(newURL, oldURL string) (string, error)
- func SetTestUtilInstance(emulatorInstance RequestMockHandler)
- func UnmarshallJSON(s string, log *zap.Logger) (interface{}, error)
- type Config
- type DiffsPrinter
- func (d *DiffsPrinter) PushBodyDiff(exp, act string, noise map[string][]string)
- func (d *DiffsPrinter) PushFooterDiff(key string)
- func (d *DiffsPrinter) PushHeaderDiff(exp, act, key string, noise map[string][]string)
- func (d *DiffsPrinter) PushStatusDiff(exp, act string)
- func (d *DiffsPrinter) Render() error
- type InstrumentState
- type Instrumentation
- type JSONComparisonResult
- type MockAction
- type MockDB
- type Replayer
- func (r *Replayer) DeleteTestSet(ctx context.Context, testSetID string) error
- func (r *Replayer) DeleteTests(ctx context.Context, testSetID string, testCaseIDs []string) error
- func (r *Replayer) DenoiseTestCases(ctx context.Context, testSetID string, noiseParams []*models.NoiseParams) ([]*models.NoiseParams, error)
- func (r *Replayer) GetAllTestSetIDs(ctx context.Context) ([]string, error)
- func (r *Replayer) GetMocks(ctx context.Context, testSetID string, afterTime time.Time, ...) (filtered, unfiltered []*models.Mock, err error)
- func (r *Replayer) GetNextTestRunID(ctx context.Context) (string, error)
- func (r *Replayer) GetTestCases(ctx context.Context, testID string) ([]*models.TestCase, error)
- func (r *Replayer) GetTestSetStatus(ctx context.Context, testRunID string, testSetID string) (models.TestSetStatus, error)
- func (r *Replayer) Instrument(ctx context.Context) (*InstrumentState, error)
- func (r *Replayer) Normalize(ctx context.Context) error
- func (r *Replayer) NormalizeTestCases(ctx context.Context, testRun string, testSetID string, ...) error
- func (r *Replayer) RunApplication(ctx context.Context, appID uint64, opts models.RunOptions) models.AppError
- func (r *Replayer) RunTestSet(ctx context.Context, testSetID string, testRunID string, appID uint64, ...) (models.TestSetStatus, error)
- func (r *Replayer) SetupOrUpdateMocks(ctx context.Context, appID uint64, testSetID string, ...) error
- func (r *Replayer) Start(ctx context.Context) error
- type ReportDB
- type RequestMockHandler
- type Service
- type Telemetry
- type TestDB
- type TestReportVerdict
- type ValidatedJSON
Constants ¶
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 AbsMatch ¶
func AbsMatch(tcs1, tcs2 *models.TestCase, noiseConfig map[string]map[string][]string, ignoreOrdering bool, logger *zap.Logger) (bool, bool, bool, *models.AbsResult)
AbsMatch (Absolute Match) compares two test cases and returns a boolean value indicating whether they are equal or not. It also returns a AbsResult object which contains the results of the comparison. Parameters: tcs1, tcs2, noiseConfig, ignoreOrdering, logger Returns: bool, *models.AbsResult
func ArrayToMap ¶
func CompareHTTPReq ¶
func CompareHTTPReq(tcs1, tcs2 *models.TestCase, _ models.GlobalNoise, ignoreOrdering bool, logger *zap.Logger) (bool, models.ReqCompare)
CompareHTTPReq compares two http requests and returns a boolean value indicating whether they are equal or not.
func CompareHTTPResp ¶
func CompareHTTPResp(tcs1, tcs2 *models.TestCase, noiseConfig models.GlobalNoise, ignoreOrdering bool, logger *zap.Logger) (bool, models.RespCompare)
CompareHTTPResp compares two http responses and returns a boolean value indicating whether they are equal or not.
func CompareHeaders ¶
func CompareNoise ¶
func CompareURLParams ¶
func CompareURLParams(urlParams1, urlParams2 map[string]string, urlParamsResult *[]models.URLParamsResult) bool
func Flatten ¶
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 InterfaceToString ¶
func InterfaceToString(val interface{}) string
func LeftJoinNoise ¶
func LeftJoinNoise(globalNoise config.GlobalNoise, tsNoise config.GlobalNoise) config.GlobalNoise
func MapToArray ¶
func ReplaceBaseURL ¶
ReplaceBaseURL replaces the baseUrl of the old URL with the new URL's.
func SetTestUtilInstance ¶
func SetTestUtilInstance(emulatorInstance RequestMockHandler)
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 InstrumentState ¶
type InstrumentState struct { AppID uint64 HookCancel context.CancelFunc }
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 GetContainerIP(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 MockAction ¶
type MockAction string
const ( Start MockAction = "start" Update MockAction = "update" )
MockAction constants define the possible actions that can be taken on a mocking.
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 Replayer ¶
type Replayer struct {
// contains filtered or unexported fields
}
func (*Replayer) DeleteTestSet ¶
func (*Replayer) DeleteTests ¶
func (*Replayer) DenoiseTestCases ¶
func (r *Replayer) DenoiseTestCases(ctx context.Context, testSetID string, noiseParams []*models.NoiseParams) ([]*models.NoiseParams, error)
func (*Replayer) GetAllTestSetIDs ¶
func (*Replayer) GetNextTestRunID ¶
func (*Replayer) GetTestCases ¶
func (*Replayer) GetTestSetStatus ¶
func (*Replayer) Instrument ¶
func (r *Replayer) Instrument(ctx context.Context) (*InstrumentState, error)
func (*Replayer) NormalizeTestCases ¶
func (*Replayer) RunApplication ¶
func (*Replayer) RunTestSet ¶
func (*Replayer) SetupOrUpdateMocks ¶
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 UpdateReport(ctx context.Context, testRunID string, testCoverage any) error }
type RequestMockHandler ¶
type RequestMockHandler interface { SimulateRequest(ctx context.Context, appID uint64, tc *models.TestCase, testSetID string) (*models.HTTPResp, error) ProcessTestRunStatus(ctx context.Context, status bool, testSetID string) FetchMockName() string ProcessMockFile(ctx context.Context, testSetID string) AfterTestHook(ctx context.Context, testRunID, testSetID string, coverage models.TestCoverage, totalTestSets int) (*models.TestReport, error) }
RequestMockHandler defines an interface for implementing hooks that extend and customize the behavior of request simulations and test workflows. This interface allows for detailed control over various stages of the testing process, including request simulation, test status processing, and post-test actions.
func NewRequestMockUtil ¶
type Service ¶
type Service interface { Start(ctx context.Context) error Instrument(ctx context.Context) (*InstrumentState, error) GetNextTestRunID(ctx context.Context) (string, 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) GetTestCases(ctx context.Context, testID string) ([]*models.TestCase, error) RunApplication(ctx context.Context, appID uint64, opts models.RunOptions) models.AppError Normalize(ctx context.Context) error DenoiseTestCases(ctx context.Context, testSetID string, noiseParams []*models.NoiseParams) ([]*models.NoiseParams, error) NormalizeTestCases(ctx context.Context, testRun string, testSetID string, selectedTestCaseIDs []string, testResult []models.TestResult) error DeleteTests(ctx context.Context, testSetID string, testCaseIDs []string) error DeleteTestSet(ctx context.Context, testSetID string) error }
type TestDB ¶
type TestDB interface { GetAllTestSetIDs(ctx context.Context) ([]string, error) GetTestCases(ctx context.Context, testSetID string) ([]*models.TestCase, error) UpdateTestCase(ctx context.Context, testCase *models.TestCase, testSetID string) error DeleteTests(ctx context.Context, testSetID string, testCaseIDs []string) error DeleteTestSet(ctx context.Context, testSetID string) 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)