it

package module
v0.0.0-...-ac398fe Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

README

CLI Integration Tests

End-to-end integration tests for the ap CLI, validating commands against real gateway and MCP server infrastructure.

Prerequisites

  • Go 1.25.1 or later
  • Docker and Docker Compose
  • Network access to pull Docker images

Important notes:

  • Docker Compose: the test runner uses the docker compose up --wait flag which requires Docker Compose v2 (the docker compose plugin). Ensure your Docker installation provides Compose v2+; older docker-compose binaries without the --wait flag will not work.

  • Configuration backup: the integration suite will temporarily back up your real CLI config file (~/.wso2ap/config.yaml) to ~/.wso2ap/config.yaml.backup and write a clean config during test execution. The original config will be restored after the suite finishes (whether tests pass or fail). If you rely on a custom local config, please be aware of this behavior.

Quick Start

# Run all integration tests
make test

# Clean up containers and logs
make clean

# Install dependencies
make deps

Configuration

Tests can be enabled/disabled by editing test-config.yaml:

tests:
  gateway:
    manage:
      - id: GW-MANAGE-001
        name: gateway add with valid parameters
        enabled: true  # Set to false to skip
        requires: [CLI, GATEWAY]

Test Structure

cli/it/
├── test-config.yaml      # Enable/disable tests
├── features/             # Gherkin feature files
│   └── gateway/
├── steps/                # Step definitions
├── resources/            # Test resources
│   └── gateway/
└── logs/                 # Test logs (git-ignored)

Infrastructure Dependencies

ID Component Description
CLI CLI Binary The ap binary built from cli/src/
GATEWAY Gateway Stack Docker Compose services: controller, router, policy-engine
MCP_SERVER MCP Server MCP backend for generate command tests

Logs

Each test writes to a separate log file in logs/:

  • logs/GW-MANAGE-001-gateway-add.log
  • logs/GW-API-001-api-list.log
  • logs/PHASE-1.log (Phase 1 infrastructure setup)
  • etc.

Documentation

See INTEGRATION-TESTS.md for detailed documentation.

Documentation

Index

Constants

View Source
const (
	ColorReset  = "\033[0m"
	ColorRed    = "\033[31m"
	ColorGreen  = "\033[32m"
	ColorYellow = "\033[33m"
	ColorBlue   = "\033[34m"
	ColorPurple = "\033[35m"
	ColorCyan   = "\033[36m"
	ColorGray   = "\033[90m"
	ColorBold   = "\033[1m"
)

ANSI color codes

View Source
const (
	// DefaultStartupTimeout is the maximum time to wait for services to become healthy
	DefaultStartupTimeout = 120 * time.Second

	// HealthCheckInterval is how often to check service health
	HealthCheckInterval = 5 * time.Second

	// GatewayControllerPort is the REST API (management) port for gateway-controller
	GatewayControllerPort = "9090"

	// GatewayControllerAdminPort is the admin (health / config_dump) port for gateway-controller
	GatewayControllerAdminPort = "9092"

	// GatewayAdminBasePath is the URL prefix under which the gateway-controller admin API
	// is served. It must stay in sync with the controller admin OpenAPI spec.
	GatewayAdminBasePath = "/api/admin/v0.9"

	// MCPServerPort is the port for MCP server
	MCPServerPort = "3001"
)

Variables

View Source
var NewCoverageCollector = coverage.NewCoverageCollector

NewCoverageCollector creates a new CoverageCollector

Functions

func CheckDockerAvailable

func CheckDockerAvailable() error

CheckDockerAvailable verifies Docker is running

func CheckPortsAvailable

func CheckPortsAvailable() error

CheckPortsAvailable verifies required ports are free

func DefaultCoverageConfig

func DefaultCoverageConfig() *coverage.CoverageConfig

DefaultCoverageConfig returns the default coverage configuration for cli/it

Types

type CoverageCollector

type CoverageCollector = coverage.CoverageCollector

CoverageCollector is an alias to the common coverage collector

type GatewayTestsConfig

type GatewayTestsConfig struct {
	Manage []TestDefinition `yaml:"manage"`
	Apply  []TestDefinition `yaml:"apply"`
	API    []TestDefinition `yaml:"api"`
	MCP    []TestDefinition `yaml:"mcp"`
	Build  []TestDefinition `yaml:"build"`
}

GatewayTestsConfig holds gateway-related test configurations

type InfrastructureConfig

type InfrastructureConfig struct {
	ComposeFile         string `yaml:"compose_file"`
	StartupTimeout      string `yaml:"startup_timeout"`
	HealthCheckInterval string `yaml:"health_check_interval"`
	DockerRegistry      string `yaml:"docker_registry"`
	ImageTag            string `yaml:"image_tag"`
}

InfrastructureConfig holds infrastructure-related configuration

type InfrastructureID

type InfrastructureID string

InfrastructureID represents infrastructure component identifiers

const (
	// InfraCLI represents the CLI binary
	InfraCLI InfrastructureID = "CLI"
	// InfraGateway represents the gateway stack (running containers)
	InfraGateway InfrastructureID = "GATEWAY"
	// InfraMCPServer represents the MCP server
	InfraMCPServer InfrastructureID = "MCP_SERVER"
)

type InfrastructureManager

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

InfrastructureManager manages the lifecycle of test infrastructure

func NewInfrastructureManager

func NewInfrastructureManager(reporter *TestReporter, cfg *TestConfig, cfgPath string) *InfrastructureManager

func (*InfrastructureManager) GetCLIBinaryPath

func (m *InfrastructureManager) GetCLIBinaryPath() string

GetCLIBinaryPath returns the path to the CLI binary

func (*InfrastructureManager) SetupInfrastructure

func (m *InfrastructureManager) SetupInfrastructure(required []InfrastructureID) error

SetupInfrastructure starts the required infrastructure components

func (*InfrastructureManager) Teardown

func (m *InfrastructureManager) Teardown() error

Teardown stops all infrastructure components

type TestConfig

type TestConfig struct {
	Infrastructure InfrastructureConfig `yaml:"infrastructure"`
	Tests          TestsConfig          `yaml:"tests"`
}

TestConfig represents the test configuration file structure

func LoadTestConfig

func LoadTestConfig(path string) (*TestConfig, error)

LoadTestConfig loads the test configuration from a YAML file

func (*TestConfig) GetAllTests

func (c *TestConfig) GetAllTests() []TestDefinition

GetAllTests returns all test definitions regardless of enabled status

func (*TestConfig) GetEnabledTests

func (c *TestConfig) GetEnabledTests() []TestDefinition

GetEnabledTests returns all enabled test definitions

func (*TestConfig) GetRequiredInfrastructure

func (c *TestConfig) GetRequiredInfrastructure() []InfrastructureID

GetRequiredInfrastructure returns unique infrastructure IDs required by enabled tests

func (*TestConfig) GetTestByID

func (c *TestConfig) GetTestByID(testID string) *TestDefinition

GetTestByID returns the test definition for a given ID

func (*TestConfig) IsTestEnabled

func (c *TestConfig) IsTestEnabled(testID string) bool

IsTestEnabled checks if a test with the given ID is enabled

type TestDefinition

type TestDefinition struct {
	ID       string   `yaml:"id"`
	Name     string   `yaml:"name"`
	Enabled  bool     `yaml:"enabled"`
	Requires []string `yaml:"requires"`
}

TestDefinition represents a single test definition

type TestReporter

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

TestReporter handles test logging and reporting

func NewTestReporter

func NewTestReporter(logsDir string) *TestReporter

NewTestReporter creates a new test reporter

func (*TestReporter) EndTest

func (r *TestReporter) EndTest(state *TestState, passed bool, errorMsg string)

EndTest completes the current test and writes the log file

func (*TestReporter) GetResults

func (r *TestReporter) GetResults() []TestResult

GetResults returns all test results

func (*TestReporter) HasFailures

func (r *TestReporter) HasFailures() bool

HasFailures returns true if any tests failed

func (*TestReporter) LogAction

func (r *TestReporter) LogAction(action string)

LogAction logs an action being performed

func (*TestReporter) LogInfo

func (r *TestReporter) LogInfo(message string)

LogInfo logs an info message

func (*TestReporter) LogPhase1

func (r *TestReporter) LogPhase1(component, message string)

LogPhase1 logs a Phase 1 infrastructure message

func (*TestReporter) LogPhase1Detail

func (r *TestReporter) LogPhase1Detail(detail string)

LogPhase1Detail logs a detailed Phase 1 step (indented)

func (*TestReporter) LogPhase1Fail

func (r *TestReporter) LogPhase1Fail(component, message, details string)

LogPhase1Fail logs a Phase 1 failure

func (*TestReporter) LogPhase1Pass

func (r *TestReporter) LogPhase1Pass(component, message string)

LogPhase1Pass logs a Phase 1 success

func (*TestReporter) LogSuccess

func (r *TestReporter) LogSuccess(message string)

LogSuccess logs a success message

func (*TestReporter) LogTest

func (r *TestReporter) LogTest(testID, testName string, passed bool, logFile string)

LogTest logs a test result (called after test completion)

func (*TestReporter) LogWaiting

func (r *TestReporter) LogWaiting(message string)

LogWaiting logs a waiting/progress message with spinner

func (*TestReporter) PrintSummary

func (r *TestReporter) PrintSummary()

PrintSummary prints the test summary with results table

func (*TestReporter) Setup

func (r *TestReporter) Setup() error

Setup initializes the reporter and creates the logs directory

func (*TestReporter) SkipTest

func (r *TestReporter) SkipTest(testID, testName, reason string)

SkipTest marks a test as skipped

func (*TestReporter) StartTest

func (r *TestReporter) StartTest(testID, testName string)

StartTest begins tracking a new test

type TestResult

type TestResult struct {
	TestID    string
	TestName  string
	Status    string // PASS, FAIL, SKIP
	Duration  time.Duration
	LogFile   string
	Error     string
	Stdout    string
	Stderr    string
	Command   []string
	ExitCode  int
	Timestamp time.Time
}

TestResult represents the result of a single test

type TestState

type TestState struct {
	// CLI execution state
	CLIBinaryPath string
	LastCommand   []string
	LastStdout    string
	LastStderr    string
	LastExitCode  int

	// Test context
	TestID     string
	TestName   string
	TempDir    string
	ConfigDir  string
	WorkingDir string

	// Gateway state
	GatewayName   string
	GatewayServer string

	// API state
	APIName    string
	APIVersion string

	// MCP state
	MCPName    string
	MCPVersion string

	// Coverage directory for CLI coverage collection
	CLICoverDir string

	// Timing
	StartTime time.Time
	EndTime   time.Time
	// contains filtered or unexported fields
}

TestState holds the state for a test scenario

func NewTestState

func NewTestState() *TestState

NewTestState creates a new test state

func (*TestState) Cleanup

func (s *TestState) Cleanup()

Cleanup cleans up the test state

func (*TestState) ExecuteCLI

func (s *TestState) ExecuteCLI(args ...string) error

ExecuteCLI executes a CLI command and captures the output

func (*TestState) GetCombinedOutput

func (s *TestState) GetCombinedOutput() string

GetCombinedOutput returns stdout and stderr combined

func (*TestState) GetConfigDir

func (s *TestState) GetConfigDir() string

GetConfigDir returns the path to the isolated test config directory

func (*TestState) GetDuration

func (s *TestState) GetDuration() time.Duration

GetDuration returns the test duration

func (*TestState) GetExitCode

func (s *TestState) GetExitCode() int

GetExitCode returns the last command's exit code

func (*TestState) GetStderr

func (s *TestState) GetStderr() string

GetStderr returns the last command's stderr

func (*TestState) GetStdout

func (s *TestState) GetStdout() string

GetStdout returns the last command's stdout

func (*TestState) Reset

func (s *TestState) Reset() error

Reset resets the test state for a new scenario

func (*TestState) SetAPIInfo

func (s *TestState) SetAPIInfo(name, version string)

SetAPIInfo sets the API information

func (*TestState) SetCLIBinaryPath

func (s *TestState) SetCLIBinaryPath(path string)

SetCLIBinaryPath sets the path to the CLI binary

func (*TestState) SetCLICoverDir

func (s *TestState) SetCLICoverDir(dir string)

SetCLICoverDir sets the directory for CLI coverage data

func (*TestState) SetGatewayInfo

func (s *TestState) SetGatewayInfo(name, server string)

SetGatewayInfo sets the gateway information

func (*TestState) SetMCPInfo

func (s *TestState) SetMCPInfo(name, version string)

SetMCPInfo sets the MCP information

func (*TestState) SetTestInfo

func (s *TestState) SetTestInfo(testID, testName string)

SetTestInfo sets the current test information

type TestsConfig

type TestsConfig struct {
	Gateway GatewayTestsConfig `yaml:"gateway"`
}

TestsConfig holds all test group configurations

Directories

Path Synopsis
Package resources provides shared test values and constants for CLI integration tests.
Package resources provides shared test values and constants for CLI integration tests.
Package steps provides step definitions for CLI integration tests.
Package steps provides step definitions for CLI integration tests.

Jump to

Keyboard shortcuts

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