mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-28 03:20:11 +00:00
test: add unit tests for types package
This commit is contained in:
parent
e4f4688fe4
commit
6f9eecec65
1 changed files with 78 additions and 0 deletions
78
internal/types/metrics_test.go
Normal file
78
internal/types/metrics_test.go
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestMetricPoint_GetTimestamp(t *testing.T) {
|
||||
now := time.Now()
|
||||
point := MetricPoint{
|
||||
Value: 42.5,
|
||||
Timestamp: now,
|
||||
}
|
||||
|
||||
result := point.GetTimestamp()
|
||||
if !result.Equal(now) {
|
||||
t.Errorf("GetTimestamp() = %v, want %v", result, now)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetricPoint_ZeroValue(t *testing.T) {
|
||||
var point MetricPoint
|
||||
|
||||
// Zero value should have zero time
|
||||
if !point.Timestamp.IsZero() {
|
||||
t.Error("Zero MetricPoint should have zero timestamp")
|
||||
}
|
||||
if point.Value != 0 {
|
||||
t.Errorf("Zero MetricPoint Value = %v, want 0", point.Value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIOMetrics_Fields(t *testing.T) {
|
||||
now := time.Now()
|
||||
metrics := IOMetrics{
|
||||
DiskRead: 1000,
|
||||
DiskWrite: 2000,
|
||||
NetworkIn: 3000,
|
||||
NetworkOut: 4000,
|
||||
Timestamp: now,
|
||||
}
|
||||
|
||||
if metrics.DiskRead != 1000 {
|
||||
t.Errorf("DiskRead = %v, want 1000", metrics.DiskRead)
|
||||
}
|
||||
if metrics.DiskWrite != 2000 {
|
||||
t.Errorf("DiskWrite = %v, want 2000", metrics.DiskWrite)
|
||||
}
|
||||
if metrics.NetworkIn != 3000 {
|
||||
t.Errorf("NetworkIn = %v, want 3000", metrics.NetworkIn)
|
||||
}
|
||||
if metrics.NetworkOut != 4000 {
|
||||
t.Errorf("NetworkOut = %v, want 4000", metrics.NetworkOut)
|
||||
}
|
||||
if !metrics.Timestamp.Equal(now) {
|
||||
t.Errorf("Timestamp = %v, want %v", metrics.Timestamp, now)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIOMetrics_ZeroValue(t *testing.T) {
|
||||
var metrics IOMetrics
|
||||
|
||||
if metrics.DiskRead != 0 {
|
||||
t.Error("Zero IOMetrics should have zero DiskRead")
|
||||
}
|
||||
if metrics.DiskWrite != 0 {
|
||||
t.Error("Zero IOMetrics should have zero DiskWrite")
|
||||
}
|
||||
if metrics.NetworkIn != 0 {
|
||||
t.Error("Zero IOMetrics should have zero NetworkIn")
|
||||
}
|
||||
if metrics.NetworkOut != 0 {
|
||||
t.Error("Zero IOMetrics should have zero NetworkOut")
|
||||
}
|
||||
if !metrics.Timestamp.IsZero() {
|
||||
t.Error("Zero IOMetrics should have zero Timestamp")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue