Moved generic and broadly useful helper functions upstream into feedkit
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
36
internal/normalizers/common/finalize_test.go
Normal file
36
internal/normalizers/common/finalize_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/ejr/feedkit/event"
|
||||
)
|
||||
|
||||
func TestFinalizeRoundsWeatherPayloadFloats(t *testing.T) {
|
||||
type payload struct {
|
||||
Value float64
|
||||
}
|
||||
|
||||
in := event.Event{
|
||||
ID: "evt-1",
|
||||
Kind: event.Kind("observation"),
|
||||
Source: "source-a",
|
||||
EmittedAt: time.Date(2026, 3, 28, 12, 0, 0, 0, time.UTC),
|
||||
Schema: "raw.example.v1",
|
||||
Payload: map[string]any{"old": true},
|
||||
}
|
||||
|
||||
out, err := Finalize(in, "weather.example.v1", payload{Value: 1.234567}, time.Time{})
|
||||
if err != nil {
|
||||
t.Fatalf("Finalize() unexpected error: %v", err)
|
||||
}
|
||||
|
||||
got, ok := out.Payload.(payload)
|
||||
if !ok {
|
||||
t.Fatalf("Finalize() payload type = %T, want payload", out.Payload)
|
||||
}
|
||||
if got.Value != 1.2346 {
|
||||
t.Fatalf("Finalize() rounded value = %v, want 1.2346", got.Value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user