framework

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 30 Imported by: 22

README

This module includes the CTFv2 harness, a lightweight, modular, and data-driven framework designed for combining off-chain and on-chain components while implementing best practices for end-to-end system-level testing:

  • Non-nil configuration: All test variables must have defaults, automatic validation.
  • Component isolation: Components are decoupled via input/output structs, without exposing internal details.
  • Modular configuration: No arcane knowledge of framework settings is required; the config is simply a reflection of the components being used in the test. Components declare their own configuration—'what you see is what you get.'
  • Replaceability and extensibility: Since components are decoupled via outputs, any deployment component can be swapped with a real service without altering the test code.
  • Integrated observability stack: use ctf obs up to spin up a local observability stack.
  • Connectivity: seamless connection of production-ready components and local components using testcontainers-go networking."

Environment variables (Tests, when using in Go code)

Name Description Possible values Default Required?
CTF_CONFIGS Path(s) to test config files.
Can be more than one, ex.: smoke.toml,smoke_1.toml,smoke_2.toml.
First filepath will hold all the merged values
Any valid TOML file path
CTF_LOG_LEVEL Harness log level info, debug, trace info 🚫
CTF_LOKI_STREAM Streams all components logs to Loki, see params below true, false false 🚫
LOKI_URL URL to Loki push api, should be like${host}/loki/api/v1/push URL - If you use Loki then ✅
LOKI_TENANT_ID Streams all components logs to Loki, see params below true, false - If you use Loki then ✅
TESTCONTAINERS_RYUK_DISABLED Testcontainers-Go reaper container, removes all the containers after the test exit true, false false 🚫
CTF_USE_CACHED_OUTPUTS Use cached .out fields from *-cache.toml config true, false false 🚫
RESTY_DEBUG Log all Resty client HTTP calls true, false false 🚫

Documentation

Index

Constants

View Source
const (
	EnvVarTestConfigs       = "CTF_CONFIGS"
	EnvVarLokiStream        = "CTF_LOKI_STREAM"
	EnvVarAWSSecretsManager = "CTF_AWS_SECRETS_MANAGER"
	// EnvVarCI this is a default env variable many CI runners use so code can detect we run in CI
	EnvVarCI = "CI"
)
View Source
const (
	OutputFieldNameTOML = "out"
	OutputFieldName     = "Out"
	OverridesFieldName  = "Overrides"
)
View Source
const (
	DefaultConfigDir = "."
)
View Source
const (
	EnvVarLogLevel = "CTF_LOG_LEVEL"
)

Variables

View Source
var (
	// Secrets is a singleton AWS Secrets Manager
	// Loaded once on start inside Load and is safe to call concurrently
	Secrets *AWSSecretsManager

	DefaultNetworkName string

	AllowedEmptyConfigurationFields = []string{OutputFieldName, OverridesFieldName}
)
View Source
var (
	PathRoot = filepath.Join(filepath.Dir(b), ".")
)

Functions

func DefaultTCLabels

func DefaultTCLabels() map[string]string

func DefaultTCName

func DefaultTCName(name string) string

func GetHost

func GetHost(container tc.Container) (string, error)

func Load

func Load[X any](t *testing.T) (*X, error)

func MapTheSamePort

func MapTheSamePort(port string) nat.PortMap

func NewLokiStreamer

func NewLokiStreamer() error

func RenderTemplate

func RenderTemplate(tmpl string, data interface{}) (string, error)

func Store

func Store[T any](cfg *T) error

func UseCache

func UseCache() bool

Types

type AWSSecret

type AWSSecret string

AWSSecret is a wrapper preventing accidental printing or marshalling

func (AWSSecret) GoString

func (s AWSSecret) GoString() string

The GoString method is used to print values passed as an operand to a %#v format.

func (AWSSecret) MarshalJSON

func (s AWSSecret) MarshalJSON() ([]byte, error)

MarshalJSON Marshaler is the interface implemented by types that can marshal themselves into valid JSON.

func (AWSSecret) MarshalText

func (s AWSSecret) MarshalText() ([]byte, error)

MarshalText encodes the receiver into UTF-8-encoded text and returns the result.

func (AWSSecret) String

func (s AWSSecret) String() string

The String method is used to print values passed as an operand to any format that accepts a string or to an unformatted printer such as Print.

func (AWSSecret) Value

func (s AWSSecret) Value() string

Value is used to return masked secret value

type AWSSecretsManager

type AWSSecretsManager struct {
	Client         *secretsmanager.Client
	RequestTimeout time.Duration
	// contains filtered or unexported fields
}

AWSSecretsManager is an AWS Secrets Manager service wrapper

func NewAWSSecretsManager

func NewAWSSecretsManager(requestTimeout time.Duration) (*AWSSecretsManager, error)

NewAWSSecretsManager create a new connection to AWS Secrets Manager

func (*AWSSecretsManager) CreateSecret

func (sm *AWSSecretsManager) CreateSecret(key string, val string, override bool) error

CreateSecret creates a specific secret by key

func (*AWSSecretsManager) GetSecret

func (sm *AWSSecretsManager) GetSecret(key string) (AWSSecret, error)

GetSecret gets a specific secret by key

func (*AWSSecretsManager) RemoveSecret

func (sm *AWSSecretsManager) RemoveSecret(key string, noRecovery bool) error

RemoveSecret removes a specific secret by key

type Config

type Config struct {
	LokiURL               string
	LokiTenantID          string
	LokiBasicAuthUsername string
	LokiBasicAuthPassword string
}

type ValidationError

type ValidationError struct {
	Field   string
	Value   interface{}
	Message string
}

Directories

Path Synopsis
components
don
dockercompose module

Jump to

Keyboard shortcuts

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