HyperSDK includes comprehensive test suites for all major components. Tests are organized by layer (provider, API, CLI) and use standard Go testing tools.
hypersdk/
├── providers/
│ ├── vsphere/
│ │ ├── infrastructure_test.go # Host/cluster/vCenter tests
│ │ ├── performance_test.go # Metrics collection tests
│ │ ├── clone_test.go # VM cloning tests
│ │ ├── resource_pools_test.go # Resource pool management tests
│ │ ├── events_test.go # Event monitoring tests
│ │ └── export_test.go # VM export tests (existing)
│ └── common/
│ └── pipeline_test.go # Pipeline integration tests
├── daemon/
│ └── api/
│ ├── vsphere_handlers_test.go # API handler tests (planned)
│ └── websocket_test.go # WebSocket streaming tests (existing)
└── cmd/
└── hyperctl/
└── vsphere_commands_test.go # CLI command tests (planned)
go test ./... -v
# All vSphere provider tests
go test ./providers/vsphere/... -v
# Specific test file
go test ./providers/vsphere/infrastructure_test.go -v
# Specific test function
go test ./providers/vsphere -run TestListHosts -v
go test ./providers/common/pipeline_test.go -v
Many tests are marked with t.Skip() as they require a running vCenter or specific setup:
# Run all non-skipped tests
go test ./providers/vsphere/... -v -short
Test individual functions and methods:
func TestHostInfoValidation(t *testing.T) {
hostInfo := HostInfo{
Name: "test-host",
CPUCores: 16,
MemoryMB: 65536,
}
assert.NotEmpty(t, hostInfo.Name)
assert.Greater(t, hostInfo.CPUCores, int32(0))
}
Test with vCenter simulator or real vCenter:
func TestListHosts(t *testing.T) {
client, cleanup := setupTestClient(t)
defer cleanup()
hosts, err := client.ListHosts(ctx, "*")
require.NoError(t, err)
assert.NotEmpty(t, hosts)
}
Note: Integration tests require:
Test complete workflows:
# Test export + pipeline + libvirt
./test_e2e_migration.sh
type mockLogger struct {
infoCalls []string
warnCalls []string
errorCalls []string
}
func (m *mockLogger) Info(msg string, keysAndValues ...interface{}) {
m.infoCalls = append(m.infoCalls, msg)
}
func setupTestClient(t *testing.T) (*VSphereClient, func()) {
// Uses vcsim (vCenter simulator) for testing
model := simulator.VPX()
err := model.Create()
// ...
cleanup := func() {
model.Remove()
}
return client, cleanup
}
Run coverage analysis:
# Generate coverage report
go test ./providers/vsphere/... -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
# View in browser
firefox coverage.html
func TestPipelineExecutor(t *testing.T) {
config := &Hyper2KVMConfig{
Enabled: true,
Hyper2KVMPath: "/usr/bin/hyper2kvm",
ManifestPath: "/tmp/manifest.json",
}
executor := NewPipelineExecutor(config, logger)
assert.NotNil(t, executor)
}
# Requires hyper2kvm and libvirt installed
go test ./providers/common/pipeline_test.go \
-run TestExecute -v
cd web/dashboard-react
npm test
# Start daemon in test mode
hyperd --test-mode &
# Run API tests
go test ./daemon/api/... -v
# Stop daemon
pkill hyperd
.github/workflows/test.yml:
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '1.24'
- name: Run tests
run: go test ./... -v -short
- name: Coverage
run: |
go test ./... -coverprofile=coverage.out
go tool cover -func=coverage.out
1. Host Information
hyperctl host -op list
hyperctl host -op info -name esxi-host-01
2. Performance Metrics
hyperctl metrics -entity test-vm -type vm -realtime
hyperctl metrics -entity test-vm -type vm -watch
3. VM Cloning
hyperctl clone -source template -target test-clone
4. Pipeline Integration
hyperexport --vm test-vm --output /tmp/test \
--manifest --pipeline --libvirt
5. Resource Pools
hyperctl pool -op create -name test-pool \
-cpu-reserve 1000 -mem-reserve 2048
6. Event Monitoring
hyperctl events -since 1h
hyperctl events -follow
go test ./providers/vsphere/... -v -run TestListHosts
# Enable detailed logging
export HYPERSDK_LOG_LEVEL=debug
go test ./providers/vsphere/... -v
go test ./... -race
go test ./providers/vsphere -memprofile=mem.prof
go tool pprof mem.prof
The vCenter Simulator (vcsim) has limitations:
Solution: Use real vCenter for critical integration tests
Some tests may timeout on slow systems:
// Increase timeout
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
Tests marked with t.Skip() require real vCenter:
func TestRealVCenter(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
// Test with real vCenter
}
Run integration tests:
# Export vCenter credentials
export VCENTER_URL=vcenter.example.com
export VCENTER_USERNAME=administrator@vsphere.local
export VCENTER_PASSWORD=password
# Run integration tests
go test ./providers/vsphere/... -v
When adding new features, include tests:
func TestNewFeature(t *testing.T) {
// Setup
client, cleanup := setupTestClient(t)
defer cleanup()
tests := []struct {
name string
input InputType
want OutputType
wantErr bool
}{
{
name: "valid input",
input: validInput,
want: expectedOutput,
wantErr: false,
},
{
name: "invalid input",
input: invalidInput,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := client.NewFeature(ctx, tt.input)
if tt.wantErr {
assert.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
}