yamlspec

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIConfig added in v0.7.1

type APIConfig struct {
	BaseURL string      `yaml:"base_url"`          // Base URL (e.g., "http://localhost:8080")
	Timeout string      `yaml:"timeout,omitempty"` // Request timeout (default: "10s")
	Auth    *AuthConfig `yaml:"auth,omitempty"`    // Optional authentication
}

APIConfig contains API configuration (simplified, protocol-agnostic)

type ApproxValidator added in v0.7.1

type ApproxValidator struct {
	Value     float64 `yaml:"value"`
	Tolerance float64 `yaml:"tolerance"`
}

ApproxValidator validates approximate float values

type ArrayValidator added in v0.7.1

type ArrayValidator struct {
	Length   *int          `yaml:"length,omitempty"`
	Contains []interface{} `yaml:"contains,omitempty"`
	Unique   bool          `yaml:"unique,omitempty"`
}

ArrayValidator validates array properties

type AuthConfig added in v0.7.1

type AuthConfig struct {
	Type   string `yaml:"type"`             // "bearer", "basic", "api_key"
	Token  string `yaml:"token,omitempty"`  // Token value
	Header string `yaml:"header,omitempty"` // Custom header name (for api_key type)
}

AuthConfig represents authentication configuration

type ExpectedError

type ExpectedError struct {
	Code    int         `yaml:"code"`              // Error code (e.g., -32601)
	Message string      `yaml:"message,omitempty"` // Error message (partial match OK)
	Data    interface{} `yaml:"data,omitempty"`    // Error data
}

ExpectedError represents an expected JSON-RPC 2.0 error

type RangeValidator added in v0.7.1

type RangeValidator struct {
	Min *float64 `yaml:"min,omitempty"`
	Max *float64 `yaml:"max,omitempty"`
}

RangeValidator validates numeric ranges

type StageSpec

type StageSpec struct {
	Stage       string     `yaml:"stage"`
	Title       string     `yaml:"title"`
	Description string     `yaml:"description,omitempty"`
	Background  string     `yaml:"background,omitempty"`
	API         APIConfig  `yaml:"api"`
	TestCases   []TestCase `yaml:"test_cases"`
}

StageSpec represents the specification for a test stage

func LoadStageSpec

func LoadStageSpec(filePath string) (*StageSpec, error)

LoadStageSpec loads a stage specification from a YAML file

func (*StageSpec) Validate added in v0.7.1

func (spec *StageSpec) Validate() error

Validate validates the entire stage specification

type TestCase

type TestCase struct {
	Slug            string     `yaml:"slug"`
	TesterLogPrefix string     `yaml:"tester_log_prefix,omitempty"`
	Title           string     `yaml:"title"`
	Description     string     `yaml:"description,omitempty"`
	Hint            string     `yaml:"hint,omitempty"`
	Tags            []string   `yaml:"tags,omitempty"`
	Setup           []TestStep `yaml:"setup,omitempty"`    // Run before main steps
	Steps           []TestStep `yaml:"steps"`              // Main test steps
	Teardown        []TestStep `yaml:"teardown,omitempty"` // Run after (always executed)
	Summary         []string   `yaml:"summary,omitempty"`
}

TestCase represents a single test case with multiple steps

func (*TestCase) Validate added in v0.7.1

func (tc *TestCase) Validate() error

Validate validates a test case

type TestStep

type TestStep struct {

	// JSON-RPC fields
	Method string                 `yaml:"method,omitempty"` // JSON-RPC method name
	Params map[string]interface{} `yaml:"params,omitempty"` // JSON-RPC params

	// REST fields
	HTTPMethod string            `yaml:"http_method,omitempty"` // GET/POST/PUT/DELETE/PATCH
	Path       string            `yaml:"path,omitempty"`        // URL path (e.g., "/api/users")
	Body       interface{}       `yaml:"body,omitempty"`        // Request body (JSON)
	Headers    map[string]string `yaml:"headers,omitempty"`     // Custom headers

	// === Response Validation ===
	Expected      interface{}      `yaml:"expected"`               // Expected result
	ExpectError   *ExpectedError   `yaml:"expect_error,omitempty"` // Expected JSON-RPC error
	ValidateRules *ValidatorConfig `yaml:"validate,omitempty"`     // Advanced validation

	// === Metadata ===
	Description string `yaml:"description"`     // Human-readable description
	Delay       int    `yaml:"delay,omitempty"` // Delay in ms before step
}

TestStep represents a single test step (auto-detects protocol) Protocol detection:

  • If "method" is set → JSON-RPC 2.0
  • If "http_method" is set → REST API

Examples:

JSON-RPC:

method: "user.create"
params: {name: "Alice"}
expected: {id: 1, name: "Alice"}

REST:

http_method: GET
path: "/health"
expected: {status: "ok"}

func (*TestStep) Validate added in v0.7.1

func (step *TestStep) Validate() error

Validate validates a test step

type ValidatorConfig added in v0.7.1

type ValidatorConfig struct {
	Range   map[string]RangeValidator  `yaml:"range,omitempty"`   // Numeric range validation
	Pattern map[string]string          `yaml:"pattern,omitempty"` // Regex pattern matching
	Type    map[string]string          `yaml:"type,omitempty"`    // Type checking
	Approx  map[string]ApproxValidator `yaml:"approx,omitempty"`  // Approximate float comparison
	Array   map[string]ArrayValidator  `yaml:"array,omitempty"`   // Array validation
}

ValidatorConfig represents advanced validation rules Applied in addition to basic "expected" validation

func (*ValidatorConfig) Validate added in v0.7.1

func (vc *ValidatorConfig) Validate() error

Validate validates the validator configuration

Jump to

Keyboard shortcuts

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