aggregator_test.go 844 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package aggregator
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func TestMetricValueToVector(t *testing.T) {
  7. t.Run("with timestamp", func(t *testing.T) {
  8. timestamp := time.Now()
  9. mv := &MetricValue{
  10. Value: 42.0,
  11. Timestamp: &timestamp,
  12. }
  13. vector := mv.ToVector()
  14. if vector.Value != 42.0 {
  15. t.Errorf("Expected value 42.0, got %f", vector.Value)
  16. }
  17. if vector.Timestamp != float64(timestamp.Unix()) {
  18. t.Errorf("Expected timestamp %f, got %f", float64(timestamp.Unix()), vector.Timestamp)
  19. }
  20. })
  21. t.Run("without timestamp", func(t *testing.T) {
  22. mv := &MetricValue{
  23. Value: 42.0,
  24. Timestamp: nil,
  25. }
  26. vector := mv.ToVector()
  27. if vector.Value != 42.0 {
  28. t.Errorf("Expected value 42.0, got %f", vector.Value)
  29. }
  30. if vector.Timestamp != 0.0 {
  31. t.Errorf("Expected timestamp 0.0, got %f", vector.Timestamp)
  32. }
  33. })
  34. }