10bfb846a8
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package infra
|
|
|
|
import "testing"
|
|
|
|
func TestCollectHostMetrics_ReturnsBasics(t *testing.T) {
|
|
samples, err := CollectHostMetrics()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if len(samples) == 0 {
|
|
t.Fatal("expected at least one sample")
|
|
}
|
|
|
|
// node_uptime_seconds es el unico colector imprescindible: debe estar siempre.
|
|
found := false
|
|
for _, s := range samples {
|
|
if s.Name == "node_uptime_seconds" {
|
|
found = true
|
|
if s.Value <= 0 {
|
|
t.Errorf("node_uptime_seconds should be positive, got %v", s.Value)
|
|
}
|
|
}
|
|
}
|
|
if !found {
|
|
t.Error("node_uptime_seconds not present in samples")
|
|
}
|
|
}
|
|
|
|
func TestCollectHostMetrics_SamplesWellFormed(t *testing.T) {
|
|
samples, err := CollectHostMetrics()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
for i, s := range samples {
|
|
if s.Name == "" {
|
|
t.Errorf("sample %d has empty Name", i)
|
|
}
|
|
// La label "instance" NO debe estar: la añade el pusher.
|
|
if _, ok := s.Labels["instance"]; ok {
|
|
t.Errorf("sample %d (%s) must not carry the instance label", i, s.Name)
|
|
}
|
|
}
|
|
}
|