fetch_ml/tests/unit/telemetry/telemetry_test.go
Jeremie Fraeys c980167041 test: implement comprehensive test suite with multiple test types
- Add end-to-end tests for complete workflow validation
- Include integration tests for API and database interactions
- Add unit tests for all major components and utilities
- Include performance tests for payload handling
- Add CLI API integration tests
- Include Podman container integration tests
- Add WebSocket and queue execution tests
- Include shell script tests for setup validation

Provides comprehensive test coverage ensuring platform reliability
and functionality across all components and interactions.
2025-12-04 16:55:13 -05:00

121 lines
2.4 KiB
Go

package telemetry
import (
"testing"
"github.com/jfraeys/fetch_ml/internal/telemetry"
)
func TestDiffIO(t *testing.T) {
t.Parallel() // Enable parallel execution
// Test normal case where after > before
before := telemetry.IOStats{
ReadBytes: 1000,
WriteBytes: 500,
}
after := telemetry.IOStats{
ReadBytes: 1500,
WriteBytes: 800,
}
delta := telemetry.DiffIO(before, after)
if delta.ReadBytes != 500 {
t.Errorf("Expected read delta 500, got %d", delta.ReadBytes)
}
if delta.WriteBytes != 300 {
t.Errorf("Expected write delta 300, got %d", delta.WriteBytes)
}
}
func TestDiffIOZero(t *testing.T) {
t.Parallel() // Enable parallel execution
// Test case where no change
stats := telemetry.IOStats{
ReadBytes: 1000,
WriteBytes: 500,
}
delta := telemetry.DiffIO(stats, stats)
if delta.ReadBytes != 0 {
t.Errorf("Expected read delta 0, got %d", delta.ReadBytes)
}
if delta.WriteBytes != 0 {
t.Errorf("Expected write delta 0, got %d", delta.WriteBytes)
}
}
func TestDiffIONegative(t *testing.T) {
t.Parallel() // Enable parallel execution
// Test case where after < before (should result in 0)
before := telemetry.IOStats{
ReadBytes: 1500,
WriteBytes: 800,
}
after := telemetry.IOStats{
ReadBytes: 1000,
WriteBytes: 500,
}
delta := telemetry.DiffIO(before, after)
// Should be 0 when after < before
if delta.ReadBytes != 0 {
t.Errorf("Expected read delta 0, got %d", delta.ReadBytes)
}
if delta.WriteBytes != 0 {
t.Errorf("Expected write delta 0, got %d", delta.WriteBytes)
}
}
func TestDiffIOEmpty(t *testing.T) {
t.Parallel() // Enable parallel execution
// Test case with empty stats
before := telemetry.IOStats{}
after := telemetry.IOStats{
ReadBytes: 1000,
WriteBytes: 500,
}
delta := telemetry.DiffIO(before, after)
if delta.ReadBytes != 1000 {
t.Errorf("Expected read delta 1000, got %d", delta.ReadBytes)
}
if delta.WriteBytes != 500 {
t.Errorf("Expected write delta 500, got %d", delta.WriteBytes)
}
}
func TestDiffIOReverse(t *testing.T) {
t.Parallel() // Enable parallel execution
// Test case with empty stats
before := telemetry.IOStats{
ReadBytes: 1000,
WriteBytes: 500,
}
after := telemetry.IOStats{}
delta := telemetry.DiffIO(before, after)
// Should be 0 when after < before
if delta.ReadBytes != 0 {
t.Errorf("Expected read delta 0, got %d", delta.ReadBytes)
}
if delta.WriteBytes != 0 {
t.Errorf("Expected write delta 0, got %d", delta.WriteBytes)
}
}