hypersdk

Testing Documentation

This directory contains all testing-related documentation for HyperSDK.

📊 Current Test Status

Total Tests: 340+ tests Daemon API Coverage: 40.8% Status: ✅ All tests passing Last Updated: 2026-01-26

Contents

Overview & Guides

Component-Specific Testing

Quick Start

Run All Tests

go test ./...

Run with Coverage

# Generate coverage profile
go test -coverprofile=coverage.out ./daemon/api

# View coverage in terminal
go tool cover -func=coverage.out

# View coverage in browser
go tool cover -html=coverage.out

Run Specific Package Tests

# API handlers
go test -v ./daemon/api

# Libvirt handlers only
go test -v ./daemon/api -run TestHandle.*Libvirt

# Jobs package
go test -v ./daemon/jobs

Run with Verbose Output

go test -v ./daemon/api

Test Organization

daemon/api Package (340+ tests)

daemon/jobs Package

Coverage by Component

High Coverage (80-100%)

✅ Authentication (100%) ✅ Cloud integrations (100%) ✅ Cost tracking (100%) ✅ Helper functions (92-100%) ✅ Libvirt snapshots (85-93%) ✅ Console operations (92-100%)

Medium Coverage (40-79%)

⚠️ Console info (54.5%) ⚠️ VNC proxy (56.2%) ⚠️ Serial device (46.2%) ⚠️ Clone/template deployment (44.8%)

Low Coverage (<40%)

❌ Backup operations (17-29%) ❌ Batch operations (15%) ❌ Clone operations (0-10%) ❌ Workflow handlers (0%) ❌ Network management (0%)

Adding New Tests

1. Create Test File

Create *_test.go file in the same package:

package api

import (
    "testing"
    "net/http/httptest"
)

func TestHandleNewFeature(t *testing.T) {
    server := setupTestBasicServer(t)
    // test implementation
}

2. Follow Test Patterns

3. Run New Tests

go test -v ./daemon/api -run TestHandleNewFeature

4. Check Coverage

go test -coverprofile=coverage.out ./daemon/api
go tool cover -func=coverage.out | grep handleNewFeature

CI/CD Integration

GitHub Actions

Tests run automatically on:

Pre-commit Hooks

# Install pre-commit hook
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
go test ./...
if [ $? -ne 0 ]; then
    echo "Tests failed. Commit aborted."
    exit 1
fi
EOF
chmod +x .git/hooks/pre-commit

Troubleshooting

Tests Timeout

Increase timeout for slow tests:

go test -timeout 30s ./daemon/api

Race Conditions

Run with race detector:

go test -race ./daemon/api

Verbose Debugging

Enable verbose output:

go test -v ./daemon/api 2>&1 | tee test-output.log

Contributing

When contributing tests:

  1. Follow existing test patterns
  2. Test both success and error paths
  3. Use descriptive test names
  4. Add comments for complex test cases
  5. Ensure tests are deterministic
  6. Update coverage metrics in test-results.md

License

Test code is licensed under LGPL-3.0-or-later.