Documentation
¶
Overview ¶
Package testutil provides test utilities for integration testing
Index ¶
- func AssertEqual(t *testing.T, expected, actual interface{}, msg string)
- func AssertLenEqual(t *testing.T, expected int, slice interface{}, msg string)
- func AssertNotEmpty(t *testing.T, value string, msg string)
- func Cleanup(t *testing.T, name string, fn func() error)
- func CompareJSON(t *testing.T, expected, actual []byte)
- func ExpectedSessionsCount(t *testing.T) int
- func ExpectedUsersCount(t *testing.T) int
- func FixturesPath(t *testing.T) string
- func GetFixtureString(t *testing.T, name string) string
- func IsSystemdAvailable() bool
- func LoadFixture(t *testing.T, name string) []byte
- func LoadFixtureJSON(t *testing.T, name string) []byte
- func NewTestContext(t *testing.T, timeout time.Duration) (context.Context, context.CancelFunc)
- func NewTestLogger(t *testing.T) zerolog.Logger
- func RequireError(t *testing.T, err error, msg string)
- func RequireNoError(t *testing.T, err error, msg string)
- func RetryWithTimeout(t *testing.T, timeout time.Duration, interval time.Duration, fn func() error) error
- func SkipIfShort(t *testing.T, reason string)
- func UnmarshalFixture(t *testing.T, name string, target interface{})
- func ValidateAllFixtures(t *testing.T)
- func ValidateFixture(t *testing.T, name string)
- type MockSocket
- type MockSocketConfig
- type SystemdTestHelper
- func (h *SystemdTestHelper) Cleanup(t *testing.T)
- func (h *SystemdTestHelper) GetServiceName() string
- func (h *SystemdTestHelper) RunSystemctl(ctx context.Context, args ...string) (string, string, error)
- func (h *SystemdTestHelper) Setup(t *testing.T) error
- func (h *SystemdTestHelper) WaitForState(ctx context.Context, expectedState string, maxWait time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEqual ¶
AssertEqual fails test if expected != actual
func AssertLenEqual ¶
AssertLenEqual fails test if slice length != expected
func AssertNotEmpty ¶
AssertNotEmpty fails test if value is empty
func CompareJSON ¶
CompareJSON compares two JSON byte arrays for equality
func ExpectedSessionsCount ¶
ExpectedSessionsCount returns expected number of sessions in "occtl -j show sessions all" fixture
func ExpectedUsersCount ¶
ExpectedUsersCount returns expected number of users in "occtl -j show users" fixture
func FixturesPath ¶
FixturesPath returns the absolute path to fixtures directory
func GetFixtureString ¶
GetFixtureString returns fixture as string (for text fixtures)
func IsSystemdAvailable ¶
func IsSystemdAvailable() bool
IsSystemdAvailable checks if systemd is available on the system
func LoadFixture ¶
LoadFixture loads a fixture file and returns its contents
func LoadFixtureJSON ¶
LoadFixtureJSON loads a fixture and validates it's valid JSON
func NewTestContext ¶
NewTestContext creates a context with timeout for testing
func NewTestLogger ¶
NewTestLogger creates a logger for testing
func RequireError ¶
RequireError fails test if error is nil
func RequireNoError ¶
RequireNoError fails test if error is not nil
func RetryWithTimeout ¶
func RetryWithTimeout(t *testing.T, timeout time.Duration, interval time.Duration, fn func() error) error
RetryWithTimeout retries a function until it succeeds or timeout
func SkipIfShort ¶
SkipIfShort skips test if -short flag is set
func UnmarshalFixture ¶
UnmarshalFixture loads and unmarshals a JSON fixture into target
func ValidateAllFixtures ¶
ValidateAllFixtures validates all expected fixture files exist and are valid JSON
func ValidateFixture ¶
ValidateFixture validates a fixture file exists and is valid JSON
Types ¶
type MockSocket ¶
type MockSocket struct {
// contains filtered or unexported fields
}
MockSocket represents a mock ocserv socket server for testing
func NewMockSocket ¶
func NewMockSocket(t *testing.T, cfg MockSocketConfig) *MockSocket
NewMockSocket creates a new mock socket helper
For compose-based testing (recommended):
mock := NewMockSocket(t, MockSocketConfig{UseCompose: true})
defer mock.Close()
For local testing (development only):
mock := NewMockSocket(t, MockSocketConfig{SocketPath: "/tmp/test.socket"})
defer mock.Close()
func (*MockSocket) SocketPath ¶
func (m *MockSocket) SocketPath() string
SocketPath returns the Unix socket path for connecting to mock server
type MockSocketConfig ¶
type MockSocketConfig struct {
// SocketPath is the path to Unix socket (default: /tmp/occtl-test-{random}.socket)
SocketPath string
// FixturesPath is the path to fixtures directory (default: ../../test/fixtures/ocserv/occtl)
FixturesPath string
// StartTimeout is max time to wait for socket to become ready (default: 5s)
StartTimeout time.Duration
// UseCompose indicates whether to use podman-compose mock-ocserv service
// If true, assumes mock-ocserv container is running with socket at /var/run/occtl.socket
UseCompose bool
// ComposeSocketVolume is the volume name for shared socket (default: mock-socket)
ComposeSocketVolume string
}
MockSocketConfig holds configuration for mock socket server
type SystemdTestHelper ¶
type SystemdTestHelper struct {
ServiceName string
ServiceFile string
UserMode bool
UnitDir string
// contains filtered or unexported fields
}
SystemdTestHelper helps manage test systemd services
func NewSystemdTestHelper ¶
func NewSystemdTestHelper(t *testing.T, serviceName string) *SystemdTestHelper
NewSystemdTestHelper creates a new systemd test helper
func (*SystemdTestHelper) Cleanup ¶
func (h *SystemdTestHelper) Cleanup(t *testing.T)
Cleanup removes the test service
func (*SystemdTestHelper) GetServiceName ¶
func (h *SystemdTestHelper) GetServiceName() string
GetServiceName returns the full service name
func (*SystemdTestHelper) RunSystemctl ¶
func (h *SystemdTestHelper) RunSystemctl(ctx context.Context, args ...string) (string, string, error)
RunSystemctl runs a systemctl command for testing
func (*SystemdTestHelper) Setup ¶
func (h *SystemdTestHelper) Setup(t *testing.T) error
Setup prepares the test service
func (*SystemdTestHelper) WaitForState ¶
func (h *SystemdTestHelper) WaitForState(ctx context.Context, expectedState string, maxWait time.Duration) error
WaitForState waits for the service to reach a specific state