opensearchtest

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const IndexSuffix = "_test"

IndexSuffix is the suffix we append to the index name when running opensearch tests, so that we don't corrupt the application's indices.

Variables

View Source
var (
	ErrCreatingRecorder = errors.New("unable to create recorder")
	ErrNoCassetteName   = errors.New("requires cassette name")
)

Functions

func IndexEditHookProvider

func IndexEditHookProvider(group string) fx.Annotated

func IsRecording

func IsRecording() bool

IsRecording returns true if copyist is currently in recording mode. We wrap the copyist.IsRecording because we re-use the same commandline flag as the copyist library, and flag.Bool doesn't like it when you have two places that listen to the same flag

func NewEditingIndexForTestingHook

func NewEditingIndexForTestingHook() opensearch.BeforeHook

func NewRecorder

func NewRecorder(options ...Options) (*recorder.Recorder, error)

NewRecorder will create a recorder configured by the RecordOptions

func SearchDelayerHookProvider

func SearchDelayerHookProvider(group string, delay time.Duration) (fx.Annotated, fx.Annotated)

func WithOpenSearchPlayback

func WithOpenSearchPlayback(options ...Options) test.Options

WithOpenSearchPlayback will setup the recorder, similar to crdb's copyist functionality where actual interactions with opensearch will be recorded, and then when the mode is set to ModeReplaying, the recorder will respond with its recorded responses. the parameter recordDelay defines how long of a delay is needed between a write to opensearch, and a read. opensearch does not immediately have writes available, so the only solution right now is to delay and reads that happen immediately after a write. For some reason, the refresh options on the index to opensearch are not working.

To control what is being matched in the http vcr, this function will provide a *MatcherBodyModifiers to uber.FX.

Types

type BulkJsonBodyMatcher

type BulkJsonBodyMatcher struct {
	Delegate ittest.RecordBodyMatcher
}

BulkJsonBodyMatcher special body matcher for OpenSearch's _bulk API See https://opensearch.org/docs/2.11/api-reference/document-apis/bulk/

func (BulkJsonBodyMatcher) Matches

func (m BulkJsonBodyMatcher) Matches(out []byte, record []byte) error

func (BulkJsonBodyMatcher) Support

func (m BulkJsonBodyMatcher) Support(contentType string) bool

type EditIndexForTestingHook

type EditIndexForTestingHook struct {
	Suffix string
}

func (*EditIndexForTestingHook) Before

func (*EditIndexForTestingHook) Order

func (e *EditIndexForTestingHook) Order() int

type Mode

type Mode recorder.Mode
const (
	ModeRecording Mode = iota
	ModeReplaying
	// ModeCommandline lets the commandline or the state in TestMain to determine the mode
	ModeCommandline
)

Recorder states

type Option

type Option struct {
	Name               string
	SavePath           string
	Mode               Mode
	RealTransport      http.RoundTripper
	SkipRequestLatency bool
	FuzzyJsonPaths     []string
	RecordDelay        time.Duration
}

type Options

type Options func(opt *Option)

func FuzzyJsonPaths

func FuzzyJsonPaths(jsonPaths ...string) Options

FuzzyJsonPaths ignore part of JSON body with JSONPath notation during playback mode. Useful for search queries with time-sensitive fields e.g. FuzzyJsonPaths("$.query.*.Time") JSONPath Syntax: https://goessner.net/articles/JsonPath/

func ReplayMode

func ReplayMode(mode Mode) Options

ReplayMode override recording/playback mode. Default is ModeCommandline

func SetRecordDelay

func SetRecordDelay(delay time.Duration) Options

SetRecordDelay add delay between each request. Note: original request latency is applied by default. This is the additional delay between each requests

func SetRecordMode

func SetRecordMode(mode Mode) Options

func SkipRequestLatency

func SkipRequestLatency(skip bool) Options

SkipRequestLatency disable mimic request latency in playback mode. Has no effect during recording By default, original request latency during recording is applied in playback mode.

type SearchDelayer

type SearchDelayer struct {
	Delay time.Duration
	// contains filtered or unexported fields
}

SearchDelayer will ensure that all searches that happen after inserting a document will have a delay so that the search can find all the documents.

func SearchDelayerHook

func SearchDelayerHook(delay time.Duration) *SearchDelayer

func (*SearchDelayer) After

func (s *SearchDelayer) After(ctx context.Context, afterContext opensearch.AfterContext) context.Context

func (*SearchDelayer) Before

func (s *SearchDelayer) Before(ctx context.Context, beforeContext opensearch.BeforeContext) context.Context

Jump to

Keyboard shortcuts

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