test

package
v0.0.0-...-ed06964 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceName       string = "Test"
	ResourceNamePlural string = "Tests"
)

Variables

View Source
var (
	IDGen = id.NewRandGenerator()
)

Functions

func NewTracetestRootSpan

func NewTracetestRootSpan(run Run) traces.Span

Types

type Assertion

type Assertion string

type AssertionExpression

type AssertionExpression struct {
	LiteralValue LiteralValue
	Operation    string
	Expression   *AssertionExpression
}

func (*AssertionExpression) String

func (e *AssertionExpression) String() string

func (*AssertionExpression) Type

func (e *AssertionExpression) Type() string

type AssertionResult

type AssertionResult struct {
	Assertion Assertion
	AllPassed bool
	Results   []SpanAssertionResult
}

type Cache

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

func NewCache

func NewCache(instanceID string, opts ...CacheOption) *Cache

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, testID id.ID, runID int) (Run, bool)

func (*Cache) Set

func (c *Cache) Set(_ context.Context, run Run) error

type CacheConfig

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

type CacheOption

type CacheOption func(*CacheConfig)

func WithMetricMeter

func WithMetricMeter(meter metric.Meter) CacheOption

type LastRun

type LastRun struct {
	Time          time.Time `json:"time,omitempty"`
	Passes        int       `json:"passes"`
	Fails         int       `json:"fails"`
	AnalyzerScore int       `json:"analyzerScore"`
}

type LiteralValue

type LiteralValue struct {
	Value string
	Type  string
}

type Output

type Output struct {
	Name     string    `json:"name,omitempty"`
	Selector SpanQuery `json:"selector,omitempty"`
	Value    string    `json:"value,omitempty" expr_enabled:"true"`
}

type Outputs

type Outputs []Output

func (*Outputs) UnmarshalJSON

func (o *Outputs) UnmarshalJSON(data []byte) error

type Repository

type Repository interface {
	List(_ context.Context, take, skip int, query, sortBy, sortDirection string) ([]Test, error)
	ListAugmented(_ context.Context, take, skip int, query, sortBy, sortDirection string) ([]Test, error)
	Count(context.Context, string) (int, error)
	SortingFields() []string

	Provision(context.Context, Test) error
	SetID(test Test, id id.ID) Test

	Get(context.Context, id.ID) (Test, error)
	GetAugmented(ctx context.Context, id id.ID) (Test, error)
	Exists(context.Context, id.ID) (bool, error)
	GetVersion(_ context.Context, _ id.ID, version int) (Test, error)

	Create(context.Context, Test) (Test, error)
	Update(context.Context, Test) (Test, error)
	Delete(context.Context, id.ID) error

	GetTestSuiteSteps(_ context.Context, _ id.ID, version int) ([]Test, error)
	DB() *sql.DB
}

func NewRepository

func NewRepository(db *sql.DB) Repository

type Run

type Run struct {
	ID          int
	TestID      id.ID
	TestVersion int

	// Timestamps
	CreatedAt                 time.Time
	ServiceTriggeredAt        time.Time
	ServiceTriggerCompletedAt time.Time
	ObtainedTraceAt           time.Time
	CompletedAt               time.Time

	// trigger params
	State   RunState
	TraceID trace.TraceID
	SpanID  trace.SpanID

	// result info
	ResolvedTrigger trigger.Trigger
	TriggerResult   trigger.TriggerResult
	Results         *RunResults
	Trace           *traces.Trace
	Outputs         maps.Ordered[string, RunOutput]
	LastError       error
	Pass            int
	Fail            int

	Metadata RunMetadata

	// variable set
	VariableSet variableset.VariableSet

	TestSuiteID         string
	TestSuiteRunID      string
	Linter              analyzer.LinterResult
	RequiredGatesResult testrunner.RequiredGatesResult
}

func NewRun

func NewRun() Run

func (Run) AssertionFailed

func (r Run) AssertionFailed(err error) Run

func (Run) ConfigureRequiredGates

func (r Run) ConfigureRequiredGates(gates []testrunner.RequiredGate) Run

func (Run) Copy

func (r Run) Copy() Run

func (Run) ExecutionTime

func (r Run) ExecutionTime() int

func (Run) Finish

func (r Run) Finish() Run

func (Run) GenerateRequiredGateResult

func (r Run) GenerateRequiredGateResult(gates []testrunner.RequiredGate) testrunner.RequiredGatesResult

func (Run) LinterError

func (r Run) LinterError(err error) Run

func (Run) RequiredGateFailed

func (r Run) RequiredGateFailed(gate testrunner.RequiredGate) Run

func (Run) ResourceID

func (r Run) ResourceID() string

func (Run) ResultsCount

func (r Run) ResultsCount() (pass, fail int)

func (Run) Start

func (r Run) Start() Run

func (Run) Stopped

func (r Run) Stopped() Run

func (Run) SuccessfulLinterExecution

func (r Run) SuccessfulLinterExecution(linter analyzer.LinterResult) Run

func (Run) SuccessfullyAsserted

func (r Run) SuccessfullyAsserted(
	outputs maps.Ordered[string, RunOutput],
	variableSet variableset.VariableSet,
	res maps.Ordered[SpanQuery, []AssertionResult],
	allPassed bool,
) Run

func (Run) SuccessfullyPolledTraces

func (r Run) SuccessfullyPolledTraces(t *traces.Trace) Run

func (Run) SuccessfullyTriggered

func (r Run) SuccessfullyTriggered() Run

func (Run) TraceFailed

func (r Run) TraceFailed(err error) Run

func (Run) TransactionStepResourceID

func (r Run) TransactionStepResourceID() string

func (Run) TriggerCompleted

func (r Run) TriggerCompleted(tr trigger.TriggerResult) Run

func (Run) TriggerFailed

func (r Run) TriggerFailed(err error) Run

func (Run) TriggerTime

func (r Run) TriggerTime() int

type RunMetadata

type RunMetadata map[string]string

type RunOutput

type RunOutput struct {
	Name     string
	Value    string
	SpanID   string
	Resolved bool
	Error    error
}

func (*RunOutput) UnmarshalJSON

func (output *RunOutput) UnmarshalJSON(data []byte) error

type RunRepository

type RunRepository interface {
	CreateRun(context.Context, Test, Run) (Run, error)
	UpdateRun(context.Context, Run) error
	DeleteRun(context.Context, Run) error
	GetRun(_ context.Context, testID id.ID, runID int) (Run, error)
	GetTestRuns(_ context.Context, _ Test, take, skip int32) ([]Run, error)
	Count(context.Context, Test) (int, error)
	GetRunByTraceID(context.Context, trace.TraceID) (Run, error)
	GetLatestRunByTestVersion(context.Context, id.ID, int) (Run, error)

	GetTestSuiteRunSteps(_ context.Context, _ id.ID, runID int) ([]Run, error)
}

func NewRunRepository

func NewRunRepository(db *sql.DB, cache *Cache) RunRepository

type RunResults

type RunResults struct {
	AllPassed bool
	Results   maps.Ordered[SpanQuery, []AssertionResult]
}

type RunState

type RunState string
const (
	RunStateCreated             RunState = "CREATED"
	RunStateExecuting           RunState = "EXECUTING"
	RunStateAwaitingTrace       RunState = "AWAITING_TRACE"
	RunStateTriggerFailed       RunState = "TRIGGER_FAILED"
	RunStateTraceFailed         RunState = "TRACE_FAILED"
	RunStateAssertionFailed     RunState = "ASSERTION_FAILED"
	RunStateAnalyzingTrace      RunState = "ANALYZING_TRACE"
	RunStateAnalyzingError      RunState = "ANALYZING_ERROR"
	RunStateFinished            RunState = "FINISHED"
	RunStateStopped             RunState = "STOPPED"
	RunStateAwaitingTestResults RunState = "AWAITING_TEST_RESULTS"
)

func (RunState) IsError

func (rs RunState) IsError() bool

func (RunState) IsFinal

func (rs RunState) IsFinal() bool

type SelectorFilter

type SelectorFilter struct {
	Property string `json:"property,omitempty"`
	Operator string `json:"operator,omitempty"`
	Value    string `json:"value,omitempty"`
}

type SelectorPseudoClass

type SelectorPseudoClass struct {
	Name     string `json:"name,omitempty"`
	Argument *int32 `json:"argument,omitempty"`
}

type SpanAssertionResult

type SpanAssertionResult struct {
	SpanID        *trace.SpanID
	ObservedValue string
	CompareErr    error
}

func (SpanAssertionResult) MarshalJSON

func (sar SpanAssertionResult) MarshalJSON() ([]byte, error)

func (SpanAssertionResult) SpanIDString

func (sar SpanAssertionResult) SpanIDString() string

func (*SpanAssertionResult) UnmarshalJSON

func (sar *SpanAssertionResult) UnmarshalJSON(data []byte) error

type SpanQuery

type SpanQuery string

func (*SpanQuery) UnmarshalJSON

func (s *SpanQuery) UnmarshalJSON(data []byte) error

type SpanSelector

type SpanSelector struct {
	Filters       []SelectorFilter     `json:"filters,omitempty"`
	PseudoClass   *SelectorPseudoClass `json:"pseudoClass,omitempty"`
	ChildSelector *SpanSelector        `json:"childSelector,omitempty"`
}

type Specs

type Specs []TestSpec

func (*Specs) UnmarshalJSON

func (ts *Specs) UnmarshalJSON(data []byte) error

type Summary

type Summary struct {
	Runs    int     `json:"runs"`
	LastRun LastRun `json:"lastRun"`
}

type Test

type Test struct {
	ID          id.ID           `json:"id,omitempty"`
	CreatedAt   *time.Time      `json:"createdAt,omitempty"`
	Name        string          `json:"name,omitempty"`
	Description string          `json:"description,omitempty"`
	Version     *int            `json:"version,omitempty"`
	Trigger     trigger.Trigger `json:"trigger,omitempty"`
	Specs       Specs           `json:"specs,omitempty"`
	Outputs     Outputs         `json:"outputs,omitempty"`
	Summary     *Summary        `json:"summary,omitempty"`
}

this struct yaml/json encoding is handled at ./test_json.go for custom encodings

func (Test) GetID

func (t Test) GetID() id.ID

func (Test) HasID

func (t Test) HasID() bool

func (Test) SafeVersion

func (t Test) SafeVersion() int

func (Test) Validate

func (t Test) Validate() error

type TestSpec

type TestSpec struct {
	Selector   SpanQuery   `json:"selector,omitempty"`
	Name       string      `json:"name,omitempty"`
	Assertions []Assertion `json:"assertions,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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