config

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultDatabase

func DefaultDatabase(databases map[string]string) (string, error)

DefaultDatabase returns the name of the first database if there is exactly one, or an error if there are zero or multiple databases and no target is specified.

func ParseMongoDBName

func ParseMongoDBName(dsn string) (string, error)

ParseMongoDBName extracts the database name from a mongodb:// URL. mongodb://user:pass@host:port/dbname → dbname

func ParseMySQLDSN

func ParseMySQLDSN(dsn string) (string, error)

ParseMySQLDSN converts a mysql:// URL into go-sql-driver/mysql format. mysql://user:pass@host:port/dbname?params → user:pass@tcp(host:port)/dbname?params

func ParseSQLiteDSN

func ParseSQLiteDSN(dsn string) string

ParseSQLiteDSN extracts the file path from a sqlite:// URL. sqlite:///path/to/db.db → /path/to/db.db sqlite://./relative.db → ./relative.db plain.db → plain.db (passthrough)

func RedactDSN

func RedactDSN(dsn string) string

RedactDSN masks the password in a DSN URL for safe logging. postgres://user:secret@host → postgres://user:***@host

func ValidateEnv

func ValidateEnv(cfg *FlowConfig, env *EnvConfig) error

ValidateEnv checks that the merged environment has the required infrastructure for all drivers referenced in the flow. Call this after MergeEnv.

Types

type APIConfig

type APIConfig struct {
	Method  string            `yaml:"method"`
	URL     string            `yaml:"url"`
	Headers map[string]string `yaml:"headers,omitempty"`
	Auth    *AuthConfig       `yaml:"auth,omitempty"`
	Body    interface{}       `yaml:"body,omitempty"`
	Timeout time.Duration     `yaml:"timeout,omitempty"`
}

APIConfig defines an HTTP request.

type APIKeyConfig

type APIKeyConfig struct {
	Header string `yaml:"header,omitempty"` // Header name (e.g., "X-API-Key")
	Query  string `yaml:"query,omitempty"`  // Query param name (e.g., "api_key")
	Value  string `yaml:"value"`            // The API key value
}

APIKeyConfig defines API key authentication. Either Header or Query should be set, not both.

type AssertConfig

type AssertConfig struct {
	Expr string `yaml:"expr"`
	Msg  string `yaml:"msg,omitempty"`
}

AssertConfig defines a single assertion.

type AuthConfig

type AuthConfig struct {
	Bearer string           `yaml:"bearer,omitempty"`  // Bearer token value
	Basic  *BasicAuthConfig `yaml:"basic,omitempty"`   // Basic auth credentials
	APIKey *APIKeyConfig    `yaml:"api_key,omitempty"` // API key auth
}

AuthConfig defines authentication configuration for HTTP requests. Only one auth method should be specified per request.

type BasicAuthConfig

type BasicAuthConfig struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

BasicAuthConfig defines HTTP Basic authentication credentials.

type CleanupStep

type CleanupStep struct {
	DBStep *DBStepConfig `yaml:"-"` // populated by custom unmarshaling
}

CleanupStep represents a post-flow cleanup action.

func (*CleanupStep) UnmarshalYAML

func (s *CleanupStep) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements custom unmarshaling to detect dynamic database keys.

type DBStepConfig

type DBStepConfig struct {
	Database string `yaml:"-"` // resolved database name (from YAML key)

	// SQL fields (Postgres, MySQL, SQLite)
	Query  string        `yaml:"query,omitempty"`
	Params []interface{} `yaml:"params,omitempty"`

	// MongoDB fields
	Collection string                 `yaml:"collection,omitempty"`
	Operation  string                 `yaml:"operation,omitempty"`
	Filter     map[string]interface{} `yaml:"filter,omitempty"`
	Document   interface{}            `yaml:"document,omitempty"`
	Documents  []interface{}          `yaml:"documents,omitempty"`
	Update     map[string]interface{} `yaml:"update,omitempty"`
}

DBStepConfig defines a database operation (SQL or document-based).

type DatabaseDriver

type DatabaseDriver string

DatabaseDriver represents a supported database type.

const (
	DriverPostgres DatabaseDriver = "postgres"
	DriverMySQL    DatabaseDriver = "mysql"
	DriverMongoDB  DatabaseDriver = "mongodb"
	DriverSQLite   DatabaseDriver = "sqlite"
)

func DetectDriver

func DetectDriver(dsn string) (DatabaseDriver, error)

DetectDriver determines the database driver from a DSN string. Supported schemes: postgres://, postgresql://, mysql://, mongodb://, mongodb+srv://, sqlite://. File paths ending in .db or .sqlite are treated as SQLite.

type EnvConfig

type EnvConfig struct {
	APIBase      string            `yaml:"api_base,omitempty"`
	Databases    map[string]string `yaml:"databases,omitempty"`
	KafkaBrokers string            `yaml:"kafka_brokers,omitempty"`
	Redis        string            `yaml:"redis,omitempty"`
}

EnvConfig holds connection strings and base URLs.

func MergeEnv

func MergeEnv(global *GlobalConfig, flow *FlowConfig, profile string) (EnvConfig, error)

MergeEnv merges global config with flow-level env, then applies profile. Priority: profile > flow > global.

type FlowConfig

type FlowConfig struct {
	Name        string        `yaml:"name"`
	Description string        `yaml:"description,omitempty"`
	Tags        []string      `yaml:"tags,omitempty"`
	Timeout     time.Duration `yaml:"timeout,omitempty"`
	FailFast    bool          `yaml:"fail_fast,omitempty"`
	Env         EnvConfig     `yaml:"env,omitempty"`
	Setup       []SetupStep   `yaml:"setup,omitempty"`
	Cleanup     []CleanupStep `yaml:"cleanup,omitempty"`
	Steps       []Step        `yaml:"steps"`
}

FlowConfig represents a complete flow file.

func LoadFlowConfig

func LoadFlowConfig(path string) (*FlowConfig, error)

LoadFlowConfig reads and parses a flow YAML file.

func LoadFlowFromJSON

func LoadFlowFromJSON(path string) (*FlowConfig, error)

LoadFlowFromJSON reads a flow definition from a JSON file.

type GlobalConfig

type GlobalConfig struct {
	Env      EnvConfig            `yaml:"env,omitempty"`
	Profiles map[string]EnvConfig `yaml:"profiles,omitempty"`
}

GlobalConfig represents the root flowtest.yaml with profiles.

func LoadGlobalConfig

func LoadGlobalConfig(path string) (*GlobalConfig, error)

LoadGlobalConfig reads the root flowtest.yaml if it exists.

type KafkaConfig

type KafkaConfig struct {
	Action  string                 `yaml:"action,omitempty"` // "produce" or "consume" (default: consume)
	Topic   string                 `yaml:"topic"`
	Timeout time.Duration          `yaml:"timeout,omitempty"`
	Match   map[string]interface{} `yaml:"match,omitempty"`
	Key     string                 `yaml:"key,omitempty"`
	Message interface{}            `yaml:"message,omitempty"` // for produce
	Headers map[string]string      `yaml:"headers,omitempty"` // for produce
}

KafkaConfig defines a Kafka produce or consume/wait operation.

type RedisConfig

type RedisConfig struct {
	Action string        `yaml:"action"`
	Key    string        `yaml:"key"`
	Value  interface{}   `yaml:"value,omitempty"`
	TTL    time.Duration `yaml:"ttl,omitempty"`
}

RedisConfig defines a Redis operation.

type RetryConfig

type RetryConfig struct {
	Times    int           `yaml:"times"`              // max retry attempts (default 1 = no retry)
	Interval time.Duration `yaml:"interval,omitempty"` // wait between retries (default 1s)
	Backoff  string        `yaml:"backoff,omitempty"`  // "linear" or "exponential" (default: linear)
}

RetryConfig defines retry behavior for flaky steps.

type ScriptConfig

type ScriptConfig struct {
	Lang       string        `yaml:"lang,omitempty"`
	Run        string        `yaml:"run"`
	AssertExit *int          `yaml:"assert_exit,omitempty"`
	Timeout    time.Duration `yaml:"timeout,omitempty"`
}

ScriptConfig defines a shell script execution.

type SeedConfig

type SeedConfig struct {
	Target string                 `yaml:"target,omitempty"` // database name; defaults to first DB if omitted
	Table  string                 `yaml:"table"`
	Data   map[string]interface{} `yaml:"data"`
}

SeedConfig defines a database seed operation.

type SetupStep

type SetupStep struct {
	Seed   *SeedConfig   `yaml:"seed,omitempty"`
	DBStep *DBStepConfig `yaml:"-"` // populated by custom unmarshaling
}

SetupStep represents a pre-flow setup action.

func (*SetupStep) UnmarshalYAML

func (s *SetupStep) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements custom unmarshaling to detect dynamic database keys.

type Step

type Step struct {
	Name   string            `yaml:"name"`
	When   string            `yaml:"when,omitempty"`
	Delay  time.Duration     `yaml:"delay,omitempty"`
	Retry  *RetryConfig      `yaml:"retry,omitempty"`
	API    *APIConfig        `yaml:"api,omitempty"`
	DBStep *DBStepConfig     `yaml:"-"` // populated by custom unmarshaling
	Kafka  *KafkaConfig      `yaml:"kafka,omitempty"`
	Redis  *RedisConfig      `yaml:"redis,omitempty"`
	Script *ScriptConfig     `yaml:"script,omitempty"`
	Assert []AssertConfig    `yaml:"assert,omitempty"`
	Save   map[string]string `yaml:"save,omitempty"`
}

Step represents a single test step in the flow.

func (*Step) DriverType

func (s *Step) DriverType() string

DriverType returns which driver this step should use.

func (*Step) UnmarshalYAML

func (s *Step) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements custom unmarshaling to detect dynamic database keys.

Jump to

Keyboard shortcuts

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