testframework

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

README ΒΆ

flagd E2E Test Framework

A comprehensive, reusable end-to-end testing framework for flagd providers across different resolver types (RPC, InProcess, File) with testcontainer integration, comprehensive debugging, and race condition fixes.

Overview

This framework provides a complete testing infrastructure that supports all flagd resolver types with unified step definitions, centralized container management, and comprehensive debugging capabilities. The framework has been completely overhauled to fix race conditions, improve event handling, and provide a more maintainable testing architecture.

Architecture Overview

πŸ—οΈ Design Principles
  • Provider Agnostic: Same step definitions work across RPC, InProcess, and File providers
  • Generic Wildcard Patterns: Future-proof step definitions using regex patterns (^a ([^\\s]+) flagd provider$)
  • Centralized Types: All types consolidated in types.go for consistency
  • Comprehensive Debugging: Built-in diagnostics infrastructure with FLAGD_E2E_DEBUG support
  • Testcontainer Integration: Full container lifecycle management with health checks
  • Separation of Concerns: Each file focuses on specific test aspects
  • Race Condition Free: Fixed RPC service initialization and event handling races
🐳 Container Integration
  • Multi-port support: RPC (8013), InProcess (8015), Launchpad (8080), Health (8014)
  • Version synchronization: Automatic testbed version detection from submodule
  • Launchpad API integration: Dynamic configuration changes and flag updates
  • Health monitoring: Real-time container state and connectivity validation

File Organization

testframework/
β”œβ”€β”€ types.go              # All type definitions and TestState
β”œβ”€β”€ utils.go              # Centralized utilities and ValueConverter
β”œβ”€β”€ step_definitions.go   # Main scenario initialization with cleanup
β”œβ”€β”€ config_steps.go       # Provider configuration testing
β”œβ”€β”€ provider_steps.go     # Generic provider lifecycle with supplier pattern
β”œβ”€β”€ flag_steps.go         # Flag evaluation with comprehensive validation
β”œβ”€β”€ context_steps.go      # Context management with targeting keys
β”œβ”€β”€ event_steps.go        # Event handling with Go channels (not arrays)
β”œβ”€β”€ testbed_runner.go     # Centralized test orchestration and container management
β”œβ”€β”€ testcontainer.go      # Testcontainer abstraction with lifecycle management
β”œβ”€β”€ debug_helper.go       # Main debug coordinator
β”œβ”€β”€ container_diagnostics.go  # Container health and port diagnostics
β”œβ”€β”€ network_diagnostics.go    # Endpoint testing and connectivity validation
β”œβ”€β”€ flag_data_inspector.go    # JSON validation and flag enumeration
β”œβ”€β”€ README.md             # This documentation
└── DEBUG_UTILS.md        # Comprehensive debugging guide

Core Architecture

TestState

Central state object with enhanced event management:

type TestState struct {
    // Provider configuration
    EnvVars      map[string]string
    ProviderType ProviderType
    Provider     openfeature.FeatureProvider
    Client       *openfeature.Client
    
    // Evaluation state with comprehensive tracking
    LastEvaluation EvaluationResult
    EvalContext    map[string]interface{}
    FlagKey        string
    FlagType       string
    DefaultValue   interface{}
    
    // Enhanced event tracking with Go channels
    EventChannel  chan EventRecord  // Replaced Java-style polling
    LastEvent     *EventRecord      // Multi-step verification support
    EventHandlers map[string]func(openfeature.EventDetails)
    
    // Container/testbed state
    Container    TestContainer
    LaunchpadURL string
    
    // Debug infrastructure
    DebugHelper  *DebugHelper
}
Provider Types with Supplier Pattern
type ProviderType int
const (
    RPC ProviderType = iota    // gRPC-based provider
    InProcess                  // HTTP sync-based provider  
    File                      // Offline file-based provider
)

// Provider supplier pattern for clean abstraction
type ProviderSupplier func(state TestState) (openfeature.FeatureProvider, error)

var (
    RPCProviderSupplier       ProviderSupplier
    InProcessProviderSupplier ProviderSupplier  
    FileProviderSupplier      ProviderSupplier
)

Framework Components

Central Test Orchestration
testbed_runner.go

Main test orchestration with enhanced container management:

Key Responsibilities:

  • Testcontainer lifecycle management with health checks
  • Container configuration and multi-port mapping
  • Network setup and connectivity validation
  • Integration with all provider types and configurations
  • Launchpad API communication for dynamic flag management

Usage Example:

runner := NewTestbedRunner(TestbedConfig{
    ProviderType: RPC,
    Tags:         []string{"~@reconnect", "~@events"},
})
defer runner.Cleanup()

// Enhanced provider supplier setup
runner.SetProviderSuppliers(
    rpcSupplier,
    inProcessSupplier, 
    fileSupplier,
)

err := runner.RunGherkinTestsWithSubtests(t, "RPC Provider Tests")
Step Definition Categories
Configuration Steps (config_steps.go)

Test provider configuration validation and environment variable handling.

Key Steps:

  • a config was initialized
  • an environment variable "([^"]*)" with value "([^"]*)"
  • an option "([^"]*)" of type "([^"]*)" with value "([^"]*)"
  • the option "([^"]*)" of type "([^"]*)" should have the value "([^"]*)"
  • we should have an error

Enhanced Features:

  • Environment variable management with automatic cleanup
  • Provider option validation with reflection
  • Configuration error testing with detailed reporting
  • Type conversion with comprehensive error handling
Provider Lifecycle Steps (provider_steps.go)

Enhanced provider management with supplier pattern and race condition fixes.

Generic Wildcard Steps:

  • ^a ([^\\s]+) flagd provider$ - Universal provider creation
  • a stable flagd provider
  • a ready event handler
  • a error event handler
  • a stale event handler
  • the ready event handler should have been executed
  • the connection is lost for (\d+)s

Race Condition Fixes:

  • RPC service initialization: Fixed race where service reported "initialized" before event stream was ready
  • Event stream connection: Proper streamReady chan error signaling
  • Provider cleanup: Enhanced cleanup between scenarios prevents contamination
Flag Evaluation Steps (flag_steps.go)

Comprehensive flag evaluation with metadata support and enhanced validation.

Key Steps:

  • a ([^-]*)-flag with key "([^"]*)" and a default value "([^"]*)"
  • the flag was evaluated with details
  • the resolved details value should be "([^"]*)"
  • the reason should be "([^"]*)"
  • the error-code should be "([^"]*)"
  • the variant should be "([^"]*)"
  • the metadata should contain key "([^"]*)" with value "([^"]*)"

Enhanced Features:

  • Multi-type flag support (Boolean, String, Integer, Float, Object)
  • Detailed evaluation result validation with comprehensive assertions
  • Metadata testing and validation
  • Error handling with specific reason codes
  • Default value management with type safety
Context Management Steps (context_steps.go)

Enhanced context handling with targeting key support.

Key Steps:

  • a context containing a key "([^"]*)", with type "([^"]*)" and with value "([^"]*)"
  • a context containing a key "([^"]*)" with value "([^"]*)"
  • an empty context
  • a context with the following keys: (data table support)
  • the targeting key is set to "([^"]*)"

Enhanced Features:

  • Dynamic context building with type validation
  • Targeting key management and validation
  • Nested context properties support
  • Data table support for complex scenarios
  • Context validation helpers with comprehensive error reporting
Event Handling Steps (event_steps.go)

Completely reworked event system using Go channels instead of Java-style arrays.

Key Steps:

  • a change event handler
  • a change event was fired
  • the flag should be part of the event payload
  • a stale event was fired
  • ^I receive a ([^\\s]+) event$ - Generic event handling

Major Improvements:

  • Go channels: EventChannel chan EventRecord instead of polling arrays
  • Non-blocking: Prevents deadlocks during event handling
  • Event isolation: Fresh channels per scenario prevent cross-contamination
  • LastEvent tracking: Multi-step event verification support
  • Timeout handling: Proper event waiting with configurable timeouts
Enhanced Utility Infrastructure
utils.go - ValueConverter

Centralized type conversion with comprehensive error handling:

type ValueConverter struct{}

// Enhanced conversion with better error handling
func (vc *ValueConverter) ConvertForSteps(value string, valueType string) (interface{}, error)

// Configuration reflection with validation
func (vc *ValueConverter) ConvertToReflectValue(valueType, value string, fieldType reflect.Type) reflect.Value

Supported Types with Validation:

  • Boolean β†’ bool (with string validation)
  • Integer/Long β†’ int64 (with overflow checks)
  • Float β†’ float64 (with precision validation)
  • String β†’ string (with encoding validation)
  • Object β†’ interface{} (with JSON validation)
  • ResolverType β†’ ProviderType (with enum validation)
  • CacheType β†’ string (with supported type validation)
Helper Functions
  • CamelToSnake() - Convert naming conventions with validation
  • ToFieldName() - Convert to Go field names with reflection
  • ValueToString() - Generic string conversion with type safety
  • StringToInt/Boolean() - Type-safe conversions with error handling
Container Integration (testcontainer.go)
Enhanced FlagdTestContainer

Comprehensive container management with health monitoring:

type FlagdTestContainer struct {
    container     testcontainers.Container
    host          string
    launchpadURL  string
    rpcPort       int
    inProcessPort int
    launchpadPort int
    healthPort    int
    
    // Enhanced monitoring
    healthChecker *HealthChecker
    diagnostics   *ContainerDiagnostics
}

Enhanced Methods:

  • GetHost() - Container host with connectivity validation
  • GetPort(service) - Service-specific ports with health checks
  • StartFlagdWithConfig(config) - Enhanced configuration via launchpad
  • TriggerFlagChange() - Simulate flag updates with verification
  • IsHealthy() - Comprehensive health validation
  • GetDiagnostics() - Real-time container diagnostics

Debug Infrastructure

πŸš€ Comprehensive Debugging (5 Specialized Components)

Enable with: FLAGD_E2E_DEBUG=true

debug_helper.go

Main debug coordinator with environment-controlled output:

  • Centralized debug state management
  • Component coordination and output formatting
  • Debug level control and filtering
container_diagnostics.go

Container health and lifecycle monitoring:

  • Real-time container state monitoring
  • Port mapping validation and connectivity tests
  • Resource usage and performance metrics
  • Container log streaming and analysis
network_diagnostics.go

Endpoint testing and connectivity validation:

  • Port accessibility testing
  • Network latency and connectivity monitoring
  • Service endpoint validation
  • Connection troubleshooting utilities
flag_data_inspector.go

JSON validation and flag enumeration:

  • Flag configuration validation and parsing
  • JSON schema validation
  • Flag enumeration and relationship mapping
  • Configuration diff analysis
Event Tracking

Complete event lifecycle monitoring:

  • Event stream connection monitoring
  • Event sequence validation and timing
  • Event payload inspection and validation
  • Event history tracking and analysis

Race Condition Fixes

RPC Service Initialization

Problem Fixed: RPC service reported "initialized" before event stream was ready.

Solution:

// Added streamReady channel for proper synchronization
type Service struct {
    streamReady chan error
    // ... other fields
}

func (s *Service) Init() error {
    // ... setup code
    return <-s.streamReady  // Wait for actual stream connection
}
Event System Overhaul

Problem Fixed: Java-style array polling caused race conditions and missed events.

Solution:

// Before: Events []EventRecord (polling)
// After: EventChannel chan EventRecord (non-blocking)
type TestState struct {
    EventChannel chan EventRecord
    LastEvent    *EventRecord
}
Provider Cleanup Enhancement

Problem Fixed: State contamination between test scenarios.

Solution:

  • Enhanced cleanupProvider() with proper shutdown
  • Clear event channels in After hooks
  • Isolated state management per scenario

Usage Examples

Basic Framework Usage
import "github.com/open-feature/go-sdk-contrib/tests/flagd/testframework"

func TestRPCProviderE2E(t *testing.T) {
    // Create runner with enhanced configuration
    runner := NewTestbedRunner(TestbedConfig{
        ProviderType: RPC,
        Tags:         []string{"~@reconnect", "~@events"},
        DebugMode:    os.Getenv("FLAGD_E2E_DEBUG") == "true",
    })
    defer runner.Cleanup()
    
    // Enhanced provider supplier setup with validation
    runner.SetProviderSuppliers(
        runner.createRPCProviderSupplier(),
        runner.createInProcessProviderSupplier(), 
        runner.createFileProviderSupplier(),
    )
    
    // Run with enhanced error handling
    err := runner.RunGherkinTestsWithSubtests(t, "RPC Provider Tests")
    require.NoError(t, err)
}
Debug Mode Usage
# Enable comprehensive debugging
FLAGD_E2E_DEBUG=true go test -v ./your-test-package

# This provides:
# - Container lifecycle monitoring
# - Network connectivity validation  
# - Flag configuration inspection
# - Event stream monitoring
# - Provider state validation
Provider-Specific Configuration
// RPC Provider with enhanced options
config := TestbedConfig{
    ProviderType: RPC,
    Tags:         []string{"~@reconnect", "~@events", "~@grace", "~@sync", "~@metadata"},
    Timeout:      30 * time.Second,
    RetryPolicy:  &RetryPolicy{MaxAttempts: 3, BackoffMs: 1000},
}

// InProcess Provider with sync configuration
config := TestbedConfig{
    ProviderType: InProcess,
    Tags:         []string{"~@grace", "~@reconnect", "~@events", "~@sync"},
    SyncEndpoint: "http://localhost:8015",
}

// File Provider with offline configuration
config := TestbedConfig{
    ProviderType: File,
    Tags:         []string{"~@reconnect", "~@sync", "~@grace", "~@events"},
    FilePath:     "/tmp/allFlags.json",
    WatchMode:    true,
}

Extension Points

Adding New Step Definitions
  1. Choose appropriate file: Add to relevant *_steps.go file based on functionality
  2. Use generic patterns: Implement wildcard regex patterns for future-proofing
  3. Register step: Add to InitializeScenario() function in step_definitions.go
  4. Update types: Add new types to types.go if needed
  5. Use utilities: Leverage ValueConverter and helpers from utils.go
  6. Add debugging: Include appropriate debug output for troubleshooting
Adding New Provider Types
  1. Update types: Add new ProviderType constant to enum
  2. Implement supplier: Add ProviderSupplier function with validation
  3. Update configuration: Add provider-specific config to TestbedConfig
  4. Test integration: Ensure container integration works with new provider
  5. Add debug support: Include provider-specific debugging capabilities
Testing New Scenarios
  1. Add feature files: Create new .feature files in testbed repository
  2. Implement steps: Add missing step definitions following generic patterns
  3. Update tag filtering: Add appropriate tags for scenario organization
  4. Test across providers: Verify scenarios work with all provider types
  5. Add documentation: Update this README with new capabilities

Performance Considerations

  • Container reuse: Efficient container lifecycle management reduces test startup time
  • Parallel execution: Framework supports parallel test execution across provider types
  • Resource cleanup: Proper cleanup prevents resource leaks and test interference
  • Optimized startup: Fast container initialization with intelligent health checks
  • Event efficiency: Non-blocking event handling prevents deadlocks and timeouts
  • Debug overhead: Debug mode can be disabled for performance-critical testing

Migration Guide

From Old Integration Package

The framework replaces the previous pkg/integration/* package:

  1. Update imports: Change to tests/flagd/testframework
  2. Use new runner: Replace old test runners with NewTestbedRunner
  3. Update step registration: Steps are automatically available through InitializeScenario()
  4. Migrate suppliers: Update provider suppliers to new signature
  5. Enable debugging: Use FLAGD_E2E_DEBUG=true for enhanced diagnostics
Benefits of Migration
  • Enhanced reliability: Fixed race conditions and improved error handling
  • Better debugging: Comprehensive debug infrastructure for troubleshooting
  • Improved maintainability: Centralized types and utilities
  • Future-proof design: Generic patterns support easy extension
  • Performance improvements: Optimized container management and event handling

This framework provides a solid foundation for comprehensive flagd provider testing while maintaining clean separation between test infrastructure and business logic. The enhanced debugging capabilities and race condition fixes significantly improve developer experience and test reliability.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var DebugMode = os.Getenv("FLAGD_E2E_DEBUG") == "true"

DebugMode controls verbose debugging output

View Source
var DefaultConverter = NewValueConverter()

Global converter instance

Functions ΒΆ

func CamelToSnake ΒΆ

func CamelToSnake(input string) string

CamelToSnake converts CamelCase to snake_case

func InitializeConfigScenario ΒΆ

func InitializeConfigScenario(ctx *godog.ScenarioContext)

InitializeConfigScenario initializes the config test scenario

func InitializeContextSteps ΒΆ added in v1.5.1

func InitializeContextSteps(ctx *godog.ScenarioContext)

initializeContextSteps registers evaluation context step definitions

func InitializeEventSteps ΒΆ added in v1.5.1

func InitializeEventSteps(ctx *godog.ScenarioContext)

InitializeEventSteps registers event handling step definitions

func InitializeFlagSteps ΒΆ added in v1.5.1

func InitializeFlagSteps(ctx *godog.ScenarioContext)

InitializeFlagSteps registers flag evaluation step definitions

func InitializeProviderSteps ΒΆ added in v1.5.1

func InitializeProviderSteps(ctx *godog.ScenarioContext)

InitializeProviderSteps registers provider lifecycle step definitions

func InitializeScenario ΒΆ

func InitializeScenario(ctx *godog.ScenarioContext)

InitializeScenario registers all step definitions for gherkin scenarios

func SetProviderSuppliers ΒΆ

func SetProviderSuppliers(rpc, inProcess, file ProviderSupplier)

SetProviderSuppliers sets the provider creation functions

func StringToBoolean ΒΆ

func StringToBoolean(str string) bool

StringToBoolean converts string to boolean with error handling

func StringToInt ΒΆ

func StringToInt(str string) int

StringToInt converts string to int with error handling

func ToFieldName ΒΆ

func ToFieldName(option string) string

ToFieldName converts option name to Go field name (capitalize first letter)

func ValueToString ΒΆ

func ValueToString(value interface{}) string

ValueToString converts any value to its string representation

Types ΒΆ

type ContainerDiagnostics ΒΆ

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

ContainerDiagnostics provides comprehensive container debugging

func NewContainerDiagnostics ΒΆ

func NewContainerDiagnostics(container TestContainer) *ContainerDiagnostics

func (*ContainerDiagnostics) HealthCheck ΒΆ

func (cd *ContainerDiagnostics) HealthCheck() map[string]interface{}

HealthCheck performs comprehensive health diagnostics

func (*ContainerDiagnostics) PrintContainerInfo ΒΆ

func (cd *ContainerDiagnostics) PrintContainerInfo()

PrintContainerInfo displays comprehensive container information

func (*ContainerDiagnostics) PrintContainerLogs ΒΆ

func (cd *ContainerDiagnostics) PrintContainerLogs(lines int)

PrintContainerLogs streams recent container logs

type ContainerInfo ΒΆ

type ContainerInfo struct {
	ID            string
	Image         string
	Host          string
	RPCPort       int
	InProcessPort int
	LaunchpadPort int
	HealthPort    int
	LaunchpadURL  string
	IsRunning     bool
	IsHealthy     bool
}

ContainerInfo provides information about the running container

type DebugHelper ΒΆ

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

DebugHelper provides high-level debugging functions

func NewDebugHelper ΒΆ

func NewDebugHelper(container TestContainer, flagsDir string) *DebugHelper

func (*DebugHelper) FullDiagnostics ΒΆ

func (dh *DebugHelper) FullDiagnostics() map[string]interface{}

FullDiagnostics runs all available diagnostics

func (*DebugHelper) GetContainerDiagnostics ΒΆ

func (dh *DebugHelper) GetContainerDiagnostics() *ContainerDiagnostics

GetContainerDiagnostics returns the container diagnostics instance

func (*DebugHelper) GetFlagDataInspector ΒΆ

func (dh *DebugHelper) GetFlagDataInspector() *FlagDataInspector

GetFlagDataInspector returns the flag data inspector instance

func (*DebugHelper) GetNetworkDiagnostics ΒΆ

func (dh *DebugHelper) GetNetworkDiagnostics() *NetworkDiagnostics

GetNetworkDiagnostics returns the network diagnostics instance

func (*DebugHelper) GetScenarioDebugger ΒΆ

func (dh *DebugHelper) GetScenarioDebugger() *ScenarioDebugger

GetScenarioDebugger returns the scenario debugger instance

type DebugLogger ΒΆ

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

DebugLogger provides structured debugging output

func NewDebugLogger ΒΆ

func NewDebugLogger(prefix string) *DebugLogger

func (*DebugLogger) PrintJSON ΒΆ

func (d *DebugLogger) PrintJSON(obj interface{}, label string)

func (*DebugLogger) Printf ΒΆ

func (d *DebugLogger) Printf(format string, args ...interface{})

type ErrorAwareProviderConfiguration ΒΆ

type ErrorAwareProviderConfiguration struct {
	Configuration *flagd.ProviderConfiguration
	Error         error
}

ErrorAwareProviderConfiguration contains a ProviderConfiguration and an error

type EvaluationResult ΒΆ

type EvaluationResult struct {
	FlagKey      string
	Value        interface{}
	Reason       openfeature.Reason
	Variant      string
	ErrorCode    openfeature.ErrorCode
	ErrorMessage string
}

EvaluationResult holds the result of flag evaluation in a generic way

type EventRecord ΒΆ

type EventRecord struct {
	Type      string
	Timestamp time.Time
	Details   openfeature.EventDetails
}

EventRecord tracks events for verification

type FlagDataInspector ΒΆ

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

FlagDataInspector helps debug flag-related issues

func NewFlagDataInspector ΒΆ

func NewFlagDataInspector(flagsDir string) *FlagDataInspector

func (*FlagDataInspector) InspectAllFlags ΒΆ

func (fdi *FlagDataInspector) InspectAllFlags() map[string]interface{}

InspectAllFlags reads and displays the contents of allFlags.json

func (*FlagDataInspector) ListFlagFiles ΒΆ

func (fdi *FlagDataInspector) ListFlagFiles() []string

ListFlagFiles shows all flag files in the directory

type FlagdContainerConfig ΒΆ

type FlagdContainerConfig struct {
	Image         string
	Tag           string
	Feature       string
	FlagsDir      string
	Networks      []string
	ExtraWaitTime time.Duration
	TestbedDir    string
}

FlagdContainerConfig holds configuration for the flagd testbed container

type FlagdTestContainer ΒΆ

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

FlagdTestContainer implements the TestContainer interface using testcontainers-go

func NewFlagdContainer ΒΆ

func NewFlagdContainer(ctx context.Context, config FlagdContainerConfig) (*FlagdTestContainer, error)

NewFlagdContainer creates a new flagd testbed container

func (*FlagdTestContainer) GetContainerLogs ΒΆ

func (f *FlagdTestContainer) GetContainerLogs(ctx context.Context) (string, error)

GetContainerLogs returns the container logs for debugging

func (*FlagdTestContainer) GetHost ΒΆ

func (f *FlagdTestContainer) GetHost() string

GetHost returns the container host

func (*FlagdTestContainer) GetInfo ΒΆ

GetInfo returns detailed information about the container

func (*FlagdTestContainer) GetLaunchpadURL ΒΆ

func (f *FlagdTestContainer) GetLaunchpadURL() string

GetLaunchpadURL returns the full URL for the launchpad API

func (*FlagdTestContainer) GetPort ΒΆ

func (f *FlagdTestContainer) GetPort(service string) int

GetPort returns the mapped port for a specific service

func (*FlagdTestContainer) IsHealthy ΒΆ

func (f *FlagdTestContainer) IsHealthy() bool

IsHealthy checks if the flagd service is healthy

func (*FlagdTestContainer) Restart ΒΆ

func (f *FlagdTestContainer) Restart(delaySeconds int) error

Restart restarts the flagd service after a delay using the launchpad API

func (*FlagdTestContainer) Start ΒΆ

func (f *FlagdTestContainer) Start() error

Start starts the container (if not already running)

func (*FlagdTestContainer) StartFlagdWithConfig ΒΆ

func (f *FlagdTestContainer) StartFlagdWithConfig(config string) error

StartFlagdWithConfig starts flagd with a specific configuration using launchpad

func (*FlagdTestContainer) Stop ΒΆ

func (f *FlagdTestContainer) Stop() error

Stop stops the container

func (*FlagdTestContainer) StopFlagd ΒΆ

func (f *FlagdTestContainer) StopFlagd() error

StopFlagd stops the flagd service using launchpad

func (*FlagdTestContainer) Terminate ΒΆ

func (f *FlagdTestContainer) Terminate() error

Terminate terminates and removes the container

func (*FlagdTestContainer) TriggerFlagChange ΒΆ

func (f *FlagdTestContainer) TriggerFlagChange() error

TriggerFlagChange triggers a flag configuration change using launchpad

type NetworkDiagnostics ΒΆ

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

NetworkDiagnostics helps debug connectivity issues

func NewNetworkDiagnostics ΒΆ

func NewNetworkDiagnostics(container TestContainer) *NetworkDiagnostics

func (*NetworkDiagnostics) TestConnectivity ΒΆ

func (nd *NetworkDiagnostics) TestConnectivity() map[string]string

TestConnectivity tests all network endpoints

type ProviderOption ΒΆ

type ProviderOption struct {
	Option    string
	ValueType string
	Value     string
}

ProviderOption is a struct to store the defined options between steps

type ProviderSupplier ΒΆ

type ProviderSupplier func(state TestState) (openfeature.FeatureProvider, error)

ProviderSupplier is a function type that creates providers

var (
	RPCProviderSupplier       ProviderSupplier
	InProcessProviderSupplier ProviderSupplier
	FileProviderSupplier      ProviderSupplier
)

Global provider supplier variables

type ProviderType ΒΆ

type ProviderType int

ProviderType represents the type of provider being tested

const (
	RPC ProviderType = iota
	InProcess
	File
)

func (ProviderType) String ΒΆ

func (p ProviderType) String() string

type ScenarioDebugger ΒΆ

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

ScenarioDebugger helps debug individual Gherkin scenarios

func NewScenarioDebugger ΒΆ

func NewScenarioDebugger() *ScenarioDebugger

func (*ScenarioDebugger) DebugScenarioFailure ΒΆ

func (sd *ScenarioDebugger) DebugScenarioFailure(scenarioName string, err error, testState interface{})

DebugScenarioFailure provides context when scenarios fail

type TestContainer ΒΆ

type TestContainer interface {
	GetHost() string
	GetPort(service string) int
	GetLaunchpadURL() string
	Start() error
	Stop() error
	Restart(delaySeconds int) error
	IsHealthy() bool
}

TestContainer interface abstracts container operations

type TestState ΒΆ

type TestState struct {
	// Provider configuration
	EnvVars      map[string]string
	ProviderType ProviderType
	Provider     openfeature.FeatureProvider
	Client       *openfeature.Client
	ConfigError  error

	// Configuration testing state
	ProviderOptions []ProviderOption
	ProviderConfig  ErrorAwareProviderConfiguration

	// Evaluation state
	LastEvaluation EvaluationResult
	EvalContext    map[string]interface{}
	TargetingKey   string
	FlagKey        string
	FlagType       string
	DefaultValue   interface{}

	// Event tracking
	EventChannel chan EventRecord // Single channel for all events
	LastEvent    *EventRecord     // Store the last received event for multiple step access

	// Container/testbed state
	Container    TestContainer
	LaunchpadURL string
	FlagDir      string
}

TestState holds all test state shared across step definitions

func GetStateFromContext ΒΆ added in v1.5.1

func GetStateFromContext(ctx context.Context) *TestState

func (*TestState) CleanupEnvironmentVariables ΒΆ

func (s *TestState) CleanupEnvironmentVariables()

cleanupEnvironmentVariables restores original environment variables

func (*TestState) GenerateOpts ΒΆ

func (s *TestState) GenerateOpts() []flagd.ProviderOption

type TestStateKey ΒΆ

type TestStateKey struct{}

TestStateKey is the key used to pass TestState across context.Context

type TestbedConfig ΒΆ added in v1.5.1

type TestbedConfig struct {
	ResolverType  ProviderType
	TestbedDir    string
	FlagsDir      string
	TestbedConfig string
	ExtraOptions  []flagd.ProviderOption
	Tag           string
	Image         string
}

TestbedConfig holds configuration for testbed runner

type TestbedRunner ΒΆ added in v1.5.1

type TestbedRunner struct {
	Tag   string
	Image string
	// contains filtered or unexported fields
}

TestbedRunner manages testbed-based e2e testing

func NewTestbedRunner ΒΆ added in v1.5.1

func NewTestbedRunner(config TestbedConfig) *TestbedRunner

NewTestbedRunner creates a new testbed-based test runner

func (*TestbedRunner) Cleanup ΒΆ added in v1.5.1

func (tr *TestbedRunner) Cleanup() error

Cleanup releases resources

func (*TestbedRunner) RunGherkinTestsWithSubtests ΒΆ added in v1.5.1

func (tr *TestbedRunner) RunGherkinTestsWithSubtests(t *testing.T, featurePaths []string, tags string) error

RunGherkinTestsWithSubtests executes gherkin tests with individual Go subtests for each scenario This makes each Gherkin scenario appear as a separate test in IntelliJ

func (*TestbedRunner) SetupContainer ΒΆ added in v1.5.1

func (tr *TestbedRunner) SetupContainer(ctx context.Context) error

SetupContainer starts and configures the flagd testbed container

type ValueConverter ΒΆ

type ValueConverter struct{}

ValueConverter provides unified type conversion for test steps

func NewValueConverter ΒΆ

func NewValueConverter() *ValueConverter

NewValueConverter creates a new value converter

func (*ValueConverter) ConvertForSteps ΒΆ

func (vc *ValueConverter) ConvertForSteps(value string, valueType string) (interface{}, error)

ConvertForSteps converts string values to appropriate types for step definitions This is the main conversion function used by step definitions

func (*ValueConverter) ConvertToReflectValue ΒΆ

func (vc *ValueConverter) ConvertToReflectValue(valueType, value string, fieldType reflect.Type) reflect.Value

ConvertToReflectValue converts string values to reflect.Value for configuration

Jump to

Keyboard shortcuts

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