| OpenHAP::Test::Integration(3p) | Perl Library Manual | OpenHAP::Test::Integration(3p) |
NAME
OpenHAP::Test::Integration - Base module for OpenHAP integration tests
SYNOPSIS
use v5.36;
use Test::More;
use OpenHAP::Test::Integration;
my $env = OpenHAP::Test::Integration->new;
$env->setup;
# Run tests...
my $response = $env->http_request('GET', '/accessories');
ok(defined $response, 'received response');
$env->teardown;
done_testing();
DESCRIPTION
Provides common setup, teardown, and utility functions for integration tests. Ensures environment is properly configured and dependencies are available.
Integration tests must run in a properly configured OpenBSD environment with all dependencies installed. Tests fail (not skip) if requirements are not met.
ENVIRONMENT
Integration tests require:
- OPENHAP_INTEGRATION_TEST environment variable set
- OpenBSD system with rcctl(8)
- openhapd and hapctl installed in /usr/local/bin
- Configuration file at /etc/openhapd.conf
- System user _openhap
- Data directory /var/db/openhapd
- mosquitto(8) installed and startable via rcctl (MQTT tests)
- mdnsd(8) and mdnsctl(8) installed, with mdnsd's flags set to a usable network interface and startable via rcctl (mDNS tests)
METHODS
new
my $env = OpenHAP::Test::Integration->new(%options);
Create a new integration test environment. Options:
setup
$env->setup;
Validate environment and prepare for testing. Dies if environment is not ready.
teardown
$env->teardown;
Clean up resources after testing, including any controller connections handed out by "get_controller".
get_controller
my $c = $env->get_controller;
$c->pair_setup or die 'pair-setup: ' . $c->last_error;
Construct an OpenHAP::Test::Controller for the configured host, port, and setup code (read from the "hap_pin" configuration key). The connection is tracked and closed in "teardown". Extra arguments are passed through to the controller constructor.
ensure_unpaired
$env->ensure_unpaired or die 'cannot unpair';
Guarantee the daemon is verifiably unpaired. When the pairings database (/var/db/openhapd/pairings.db) holds any entry, the daemon is stopped, the pairing state is wiped - pairings.db and auth_attempts, keeping the accessory identity - and the daemon is started again. The post-condition is then probed with POST /identify, which returns 204 only while unpaired; a paired answer fails the call. Returns true on a verified unpaired daemon, false otherwise. Every integration test file starts unpaired unless it pairs itself.
http_request
my $response = $env->http_request($method, $path, $body, $headers);
Make an HTTP request to the HAP server. The connection stays open and registered until "teardown" (or "close_sockets").
close_sockets
$env->close_sockets;
Close and forget every raw socket opened by "http_request", so a probe connection is not left registered with the daemon until teardown.
parse_http_response
my ($status, $headers, $body) =
OpenHAP::Test::Integration::parse_http_response($response);
Parse an HTTP response.
get_config_value
my $value = $env->get_config_value($key);
Get a configuration value.
get_device_topics
my @topics = $env->get_device_topics;
Get all device MQTT topics.
get_devices
my ($light) = grep { $_->{subtype} eq 'lightbulb' } $env->get_devices;
Get the configured device records: hashes with "type", "subtype", "id", "name", and "topic".
ensure_daemon_running
$env->ensure_daemon_running or die "Cannot start daemon";
Ensure openhapd is running.
ensure_daemon_stopped
$env->ensure_daemon_stopped;
Ensure openhapd is stopped.
ensure_mqtt_running
$env->ensure_mqtt_running or die "MQTT required";
Ensure MQTT broker is running.
ensure_mdnsd_running
$env->ensure_mdnsd_running or die "mdnsd required";
Ensure mdnsd is running and stays running: start it if needed, then re-check across a settle window, because a point-in-time probe races green when mdnsd starts and then exits shortly after. On failure, captured diagnostics (rcctl state, process list, recent syslog lines) are emitted as warnings.
get_log_lines
my @lines = $env->get_log_lines($pattern);
Get log lines matching pattern since baseline.
get_mqtt
my $mqtt = $env->get_mqtt;
Get MQTT client connection.
AUTHOR
Dick Olsson <hi@senzilla.io>
| 2026-07-27 | OpenBSD |