runner

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTraceTestResultsProto

func BuildTraceTestResultsProto(e *Executor, results []TestResult, tests []Test) []*backend.TraceTestResult

func ConvertRunnerResultToTraceTestResult

func ConvertRunnerResultToTraceTestResult(result TestResult, test Test) *backend.TraceTestResult

func ConvertRunnerResultsToTraceTestResults

func ConvertRunnerResultsToTraceTestResults(results []TestResult, tests []Test) []*backend.TraceTestResult

ConvertRunnerResultsToTraceTestResults maps local results for upload to the backend

func OutputResults

func OutputResults(results []TestResult, tests []Test, format string, quiet bool) error

func ParseBodyForComparison

func ParseBodyForComparison(decodedBytes []byte, decodedType DecodedType) (any, error)

ParseBodyForComparison parses decoded body bytes for response comparison. For JSON, it unmarshals into a structured type; for text, returns string. For binary/media types, returns base64-encoded string for comparison.

func UploadResultsAndFinalize

func UploadResultsAndFinalize(
	ctx context.Context,
	client *api.TuskClient,
	driftRunID string,
	authOptions api.AuthOptions,
	executor *Executor,
	results []TestResult,
	tests []Test,
	streamed bool,
) error

func UploadSingleTestResult

func UploadSingleTestResult(
	ctx context.Context,
	client *api.TuskClient,
	driftRunID string,
	auth api.AuthOptions,
	e *Executor,
	res TestResult,
	test Test,
) error

Types

type DecodedType

type DecodedType string

DecodedType represents the type of decoded content. Must match the DecodedType enum in tusk-drift-sdk/src/core/tracing/JsonSchemaHelper.ts. TODO: use Protobuf to share this type across the CLI and SDK(s).

const (
	DecodedTypeJSON          DecodedType = "JSON"
	DecodedTypeHTML          DecodedType = "HTML"
	DecodedTypeCSS           DecodedType = "CSS"
	DecodedTypeJAVASCRIPT    DecodedType = "JAVASCRIPT"
	DecodedTypeXML           DecodedType = "XML"
	DecodedTypeYAML          DecodedType = "YAML"
	DecodedTypeMARKDOWN      DecodedType = "MARKDOWN"
	DecodedTypeCSV           DecodedType = "CSV"
	DecodedTypeSQL           DecodedType = "SQL"
	DecodedTypeGRAPHQL       DecodedType = "GRAPHQL"
	DecodedTypePLAINTEXT     DecodedType = "PLAIN_TEXT"
	DecodedTypeFORMDATA      DecodedType = "FORM_DATA"
	DecodedTypeMULTIPARTFORM DecodedType = "MULTIPART_FORM"
	DecodedTypePDF           DecodedType = "PDF"
	DecodedTypeAUDIO         DecodedType = "AUDIO"
	DecodedTypeVIDEO         DecodedType = "VIDEO"
	DecodedTypeGZIP          DecodedType = "GZIP"
	DecodedTypeBINARY        DecodedType = "BINARY"
	DecodedTypeJPEG          DecodedType = "JPEG"
	DecodedTypePNG           DecodedType = "PNG"
	DecodedTypeGIF           DecodedType = "GIF"
	DecodedTypeWEBP          DecodedType = "WEBP"
	DecodedTypeSVG           DecodedType = "SVG"
	DecodedTypeZIP           DecodedType = "ZIP"
	DecodedTypeUNSPECIFIED   DecodedType = "UNSPECIFIED"
)

func DecodeBody

func DecodeBody(bodyValue any, metadata *RequestBodyMetadata) ([]byte, DecodedType, error)

DecodeBody decodes a body value using schema metadata Returns the decoded bytes and the type for further processing

type Deviation

type Deviation struct {
	Field       string `json:"field"`
	Expected    any    `json:"expected"`
	Actual      any    `json:"actual"`
	Description string `json:"description"`
}

type DynamicFieldMatcher

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

DynamicFieldMatcher defines patterns for identifying dynamic fields that should be ignored

func NewDynamicFieldMatcher

func NewDynamicFieldMatcher() *DynamicFieldMatcher

NewDynamicFieldMatcher creates a new matcher with default patterns

func NewDynamicFieldMatcherWithConfig

func NewDynamicFieldMatcherWithConfig(cfg *config.ComparisonConfig) *DynamicFieldMatcher

func (*DynamicFieldMatcher) ShouldIgnoreField

func (m *DynamicFieldMatcher) ShouldIgnoreField(fieldName string, expectedValue, actualValue any, testID string) bool

ShouldIgnoreField determines if a field should be ignored during comparison

type EncodingType

type EncodingType string

EncodingType represents how the body is encoded

const (
	EncodingTypeBASE64 EncodingType = "BASE64"
	EncodingTypeNONE   EncodingType = "NONE"
)

type Executor

type Executor struct {
	ResultsFile string // Will be set by the run command if --save-results is true
	// contains filtered or unexported fields
}

func NewExecutor

func NewExecutor() *Executor

func (*Executor) GetConcurrency

func (e *Executor) GetConcurrency() int

GetConcurrency returns the current concurrency setting

func (*Executor) GetServer added in v0.1.1

func (e *Executor) GetServer() *Server

GetServer returns the server instance

func (*Executor) GetServiceLogPath

func (e *Executor) GetServiceLogPath() string

func (*Executor) LoadSpansForTrace

func (e *Executor) LoadSpansForTrace(traceID string, filename string) ([]*core.Span, error)

func (*Executor) LoadTestsFromFolder

func (e *Executor) LoadTestsFromFolder(folder string) ([]Test, error)

func (*Executor) LoadTestsFromTraceFile

func (e *Executor) LoadTestsFromTraceFile(path string) ([]Test, error)

LoadTestsFromTraceFile loads all tests from a trace file

func (*Executor) RunSingleTest

func (e *Executor) RunSingleTest(test Test) (TestResult, error)

RunSingleTest replays a single trace on the service under test.

func (*Executor) RunTests

func (e *Executor) RunTests(tests []Test) ([]TestResult, error)

func (*Executor) RunTestsConcurrently

func (e *Executor) RunTestsConcurrently(tests []Test, maxConcurrency int) ([]TestResult, error)

RunTestsConcurrently executes tests in parallel with the specified concurrency limit

func (*Executor) SetConcurrency

func (e *Executor) SetConcurrency(concurrency int)

SetConcurrency sets the maximum number of concurrent tests

func (*Executor) SetEnableServiceLogs

func (e *Executor) SetEnableServiceLogs(enable bool)

SetDisableServiceLogs sets whether service logging should be disabled

func (*Executor) SetOnTestCompleted

func (e *Executor) SetOnTestCompleted(callback func(TestResult, Test))

func (*Executor) SetResultsOutput

func (e *Executor) SetResultsOutput(dir string)

func (*Executor) SetSuiteSpans

func (e *Executor) SetSuiteSpans(spans []*core.Span)

func (*Executor) SetTestTimeout

func (e *Executor) SetTestTimeout(timeout time.Duration)

func (*Executor) StartEnvironment

func (e *Executor) StartEnvironment() error

StartEnvironment starts the mock server and service, then waits for the SDK ack. It performs best-effort cleanup on failure.

func (*Executor) StartServer

func (e *Executor) StartServer() error

StartServer initializes and starts the mock server

func (*Executor) StartService

func (e *Executor) StartService() error

func (*Executor) StopEnvironment

func (e *Executor) StopEnvironment() error

StopEnvironment stops the service and mock server (best effort).

func (*Executor) StopServer

func (e *Executor) StopServer() error

func (*Executor) StopService

func (e *Executor) StopService() error

func (*Executor) WaitForSDKAcknowledgement

func (e *Executor) WaitForSDKAcknowledgement() error

WaitForSDKAcknowledgement waits for the SDK to acknowledge the connection.

func (*Executor) WaitForSpanData

func (e *Executor) WaitForSpanData(traceID string, timeout time.Duration)

WaitForSpanData blocks briefly until inbound or match events are recorded for a test

func (*Executor) WriteRunResultsToFile

func (e *Executor) WriteRunResultsToFile(tests []Test, results []TestResult) (string, error)

type MatchEvent

type MatchEvent struct {
	SpanID     string              `json:"spanId"`
	MatchLevel *backend.MatchLevel `json:"matchLevel"`
	StackTrace string              `json:"stackTrace"`
	InputData  map[string]any      `json:"inputData,omitempty"`
	Timestamp  time.Time           `json:"timestamp"`
	ReplaySpan *core.Span          `json:"replaySpan,omitempty"`
}

type MessageType

type MessageType string

MessageType represents the type of message sent by the SDK

const (
	MessageTypeSDKConnect  MessageType = "sdk_connect"
	MessageTypeMockRequest MessageType = "mock_request"
)

type MockMatcher

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

func NewMockMatcher

func NewMockMatcher(server *Server) *MockMatcher

func (*MockMatcher) FindBestMatchAcrossTraces

func (mm *MockMatcher) FindBestMatchAcrossTraces(req *core.GetMockRequest, traceID string, spans []*core.Span) (*core.Span, *backend.MatchLevel, error)

FindBestMatchInSpans implements the priority matching algorithm for spans across a test suite

func (*MockMatcher) FindBestMatchInTrace

func (mm *MockMatcher) FindBestMatchInTrace(req *core.GetMockRequest, traceID string) (*core.Span, *backend.MatchLevel, error)

FindBestMatch implements the priority matching algorithm for spans within a trace

type MockMatcherRequestData

type MockMatcherRequestData struct {
	InputValue      any
	InputValueHash  string
	InputSchema     any
	InputSchemaHash string
}

type MockNotFoundEvent added in v0.1.1

type MockNotFoundEvent struct {
	PackageName string    `json:"packageName"`
	SpanName    string    `json:"spanName"`   // e.g., "GET /api/users" or "pg.query"
	Operation   string    `json:"operation"`  // "GET", "POST", "query", etc.
	StackTrace  string    `json:"stackTrace"` // Code location that made the call
	Timestamp   time.Time `json:"timestamp"`
	Error       string    `json:"error"` // Full error message
}

type Request

type Request struct {
	Method  string            `json:"method"`
	Path    string            `json:"path"`
	Headers map[string]string `json:"headers"`
	Body    any               `json:"body,omitempty"`
}

type RequestBodyMetadata

type RequestBodyMetadata struct {
	Encoding    EncodingType
	DecodedType DecodedType
}

RequestBodyMetadata contains encoding information from the schema

func ExtractRequestBodyMetadata

func ExtractRequestBodyMetadata(schema *structpb.Struct, fieldPath string) *RequestBodyMetadata

ExtractBodyMetadata extracts encoding metadata from a schema for a specific field

type Response

type Response struct {
	Status  int               `json:"status"`
	Headers map[string]string `json:"headers"`
	Body    any               `json:"body,omitempty"`
}

type SemVer

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

type Server

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

Server handles Unix socket communication with the SDK

func NewServer

func NewServer(serviceID string) (*Server, error)

NewServer creates a new server instance

func (*Server) GetInboundReplaySpan

func (ms *Server) GetInboundReplaySpan(traceID string) *core.Span

func (*Server) GetMatchEvents

func (ms *Server) GetMatchEvents(traceID string) []MatchEvent

func (*Server) GetMockNotFoundEvents added in v0.1.1

func (ms *Server) GetMockNotFoundEvents(traceID string) []MockNotFoundEvent

func (*Server) GetRootSpanID

func (ms *Server) GetRootSpanID(traceID string) string

func (*Server) GetSDKVersion

func (ms *Server) GetSDKVersion() string

func (*Server) GetSocketPath

func (ms *Server) GetSocketPath() string

func (*Server) GetSuiteSpans

func (ms *Server) GetSuiteSpans() []*core.Span

func (*Server) HasMockNotFoundEvents added in v0.1.1

func (ms *Server) HasMockNotFoundEvents(traceID string) bool

func (*Server) LoadSpansForTrace

func (ms *Server) LoadSpansForTrace(traceID string, spans []*core.Span)

LoadSpansForTrace loads all spans for matching

func (*Server) SetCurrentTestID

func (ms *Server) SetCurrentTestID(id string)

func (*Server) SetSuiteSpans

func (ms *Server) SetSuiteSpans(spans []*core.Span)

func (*Server) Start

func (ms *Server) Start() error

Start begins listening on the Unix socket

func (*Server) Stop

func (ms *Server) Stop() error

Stop shuts down the mock server

func (*Server) WaitForInboundSpan

func (ms *Server) WaitForInboundSpan(traceID string, timeout time.Duration)

func (*Server) WaitForSDKConnection

func (ms *Server) WaitForSDKConnection(timeout time.Duration) error

func (*Server) WaitForSpanData

func (ms *Server) WaitForSpanData(traceID string, timeout time.Duration)

type Test

type Test struct {
	FileName    string         `json:"file_name"`
	TraceID     string         `json:"trace_id"`
	TraceTestID string         `json:"trace_test_id,omitempty"`
	Spans       []*core.Span   `json:"-"`
	Type        string         `json:"type"`         // Used for test execution
	DisplayType string         `json:"display_type"` // Used for CLI display
	Timestamp   string         `json:"timestamp"`
	Method      string         `json:"method"`
	Path        string         `json:"path"`         // Used for test execution
	DisplayName string         `json:"display_name"` // Used for CLI display
	Status      string         `json:"status"`
	Duration    int            `json:"duration"`
	Metadata    map[string]any `json:"metadata"`
	Request     Request        `json:"request"`
	Response    Response       `json:"response"`
}

func ConvertTraceTestToRunnerTest

func ConvertTraceTestToRunnerTest(tt *backend.TraceTest) Test

ConvertTraceTestToRunnerTest converts a single protobuf TraceTest to runner.Test

func ConvertTraceTestsToRunnerTests

func ConvertTraceTestsToRunnerTests(traceTests []*backend.TraceTest) []Test

ConvertTraceTestsToRunnerTests converts protobuf TraceTests to runner.Tests

func FilterTests

func FilterTests(tests []Test, pattern string) ([]Test, error)

type TestResult

type TestResult struct {
	TestID     string      `json:"test_id"`
	Passed     bool        `json:"passed"`
	Duration   int         `json:"duration"` // In milliseconds
	Deviations []Deviation `json:"deviations,omitempty"`
	Error      string      `json:"error,omitempty"`
}

type Trace

type Trace struct {
	ID        string       `json:"id"`
	Filename  string       `json:"filename"`
	Timestamp string       `json:"timestamp"`
	Spans     []*core.Span `json:"spans"`
}

Jump to

Keyboard shortcuts

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