replay

package
v2.3.0-beta40 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package replay provides the hooks for the replay service

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LeftJoinNoise

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

func ReplaceBaseURL

func ReplaceBaseURL(newURL, oldURL string) (string, error)

ReplaceBaseURL replaces the baseUrl of the old URL with the new URL's.

func SetTestHooks

func SetTestHooks(testHooks TestHooks)

Types

type Hooks

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

func (*Hooks) AfterTestRun

func (h *Hooks) AfterTestRun(_ context.Context, testRunID string, testSetIDs []string, coverage models.TestCoverage) error

func (*Hooks) AfterTestSetRun

func (h *Hooks) AfterTestSetRun(ctx context.Context, testSetID string, status bool) error

func (*Hooks) BeforeTestSetRun

func (h *Hooks) BeforeTestSetRun(ctx context.Context, testSetID string) error

func (*Hooks) SimulateRequest

func (h *Hooks) SimulateRequest(ctx context.Context, _ uint64, tc *models.TestCase, testSetID string) (*models.HTTPResp, error)

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 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 (r *Replayer) DeleteTestSet(ctx context.Context, testSetID string) error

func (*Replayer) DeleteTests

func (r *Replayer) DeleteTests(ctx context.Context, testSetID string, testCaseIDs []string) error

func (*Replayer) DenoiseTestCases

func (r *Replayer) DenoiseTestCases(ctx context.Context, testSetID string, noiseParams []*models.NoiseParams) ([]*models.NoiseParams, error)

func (*Replayer) GetAllTestSetIDs

func (r *Replayer) GetAllTestSetIDs(ctx context.Context) ([]string, error)

func (*Replayer) GetMocks

func (r *Replayer) GetMocks(ctx context.Context, testSetID string, afterTime time.Time, beforeTime time.Time) (filtered, unfiltered []*models.Mock, err error)

func (*Replayer) GetNextTestRunID

func (r *Replayer) GetNextTestRunID(ctx context.Context) (string, error)

func (*Replayer) GetTestCases

func (r *Replayer) GetTestCases(ctx context.Context, testID string) ([]*models.TestCase, error)

func (*Replayer) GetTestSetConf

func (r *Replayer) GetTestSetConf(ctx context.Context, testSet string) (*models.TestSet, error)

func (*Replayer) GetTestSetStatus

func (r *Replayer) GetTestSetStatus(ctx context.Context, testRunID string, testSetID string) (models.TestSetStatus, error)

func (*Replayer) Instrument

func (r *Replayer) Instrument(ctx context.Context) (*InstrumentState, error)

func (*Replayer) Normalize

func (r *Replayer) Normalize(ctx context.Context) error

func (*Replayer) NormalizeTestCases

func (r *Replayer) NormalizeTestCases(ctx context.Context, testRun string, testSetID string, selectedTestCaseIDs []string, testCaseResults []models.TestResult) error

func (*Replayer) RunApplication

func (r *Replayer) RunApplication(ctx context.Context, appID uint64, opts models.RunOptions) models.AppError

func (*Replayer) RunTestSet

func (r *Replayer) RunTestSet(ctx context.Context, testSetID string, testRunID string, appID uint64, serveTest bool) (models.TestSetStatus, error)

func (*Replayer) SetupOrUpdateMocks

func (r *Replayer) SetupOrUpdateMocks(ctx context.Context, appID uint64, testSetID string, afterTime, beforeTime time.Time, action MockAction) error

func (*Replayer) Start

func (r *Replayer) Start(ctx context.Context) error

func (*Replayer) Templatize

func (r *Replayer) Templatize(ctx context.Context) 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
	UpdateReport(ctx context.Context, testRunID string, testCoverage any) error
}

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)
	GetTestSetConf(ctx context.Context, testSetID string) (*models.TestSet, error)
	RunApplication(ctx context.Context, appID uint64, opts models.RunOptions) models.AppError
	Normalize(ctx context.Context) error
	Templatize(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
}

func NewReplayer

func NewReplayer(logger *zap.Logger, testDB TestDB, mockDB MockDB, reportDB ReportDB, testSetConf TestSetConfig, telemetry Telemetry, instrumentation Instrumentation, auth service.Auth, storage Storage, config *config.Config) Service

type Storage

type Storage interface {
	Upload(ctx context.Context, file io.Reader, mockName string, appName string, jwtToken string) error
	Download(ctx context.Context, mockName string, appName string, userName string, jwtToken string) (io.Reader, error)
}

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)
	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 TestHooks

type TestHooks interface {
	SimulateRequest(ctx context.Context, appID uint64, tc *models.TestCase, testSetID string) (*models.HTTPResp, error)
	BeforeTestSetRun(ctx context.Context, testSetID string) error
	AfterTestSetRun(ctx context.Context, testSetID string, status bool) error
	AfterTestRun(ctx context.Context, testRunID string, testSetIDs []string, coverage models.TestCoverage) error // hook executed after running all the test-sets
}
var HookImpl TestHooks

func NewHooks

func NewHooks(logger *zap.Logger, cfg *config.Config, tsConfigDB TestSetConfig, storage Storage, auth service.Auth) TestHooks

type TestReportVerdict

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

type TestSetConfig

type TestSetConfig interface {
	Read(ctx context.Context, testSetID string) (*models.TestSet, error)
	Write(ctx context.Context, testSetID string, testSet *models.TestSet) error
}

Jump to

Keyboard shortcuts

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