Updated the normalized observation schema to remove duplicate and/or unnecessary fields
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:
61
internal/normalizers/openmeteo/observation_test.go
Normal file
61
internal/normalizers/openmeteo/observation_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package openmeteo
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBuildObservationTextDescriptionAndPressurePrecedence(t *testing.T) {
|
||||
weatherCode := 2
|
||||
pressureMSL := 1016.0
|
||||
surfacePressure := 1009.0
|
||||
|
||||
parsed := omResponse{
|
||||
Timezone: "UTC",
|
||||
UTCOffsetSeconds: 0,
|
||||
Current: omCurrent{
|
||||
Time: "2026-03-16T19:00",
|
||||
WeatherCode: &weatherCode,
|
||||
PressureMSL: &pressureMSL,
|
||||
SurfacePressure: &surfacePressure,
|
||||
},
|
||||
}
|
||||
|
||||
obs, _, err := buildObservation(parsed)
|
||||
if err != nil {
|
||||
t.Fatalf("buildObservation() error = %v", err)
|
||||
}
|
||||
|
||||
if got, want := obs.TextDescription, "Partly Cloudy"; got != want {
|
||||
t.Fatalf("TextDescription = %q, want %q", got, want)
|
||||
}
|
||||
|
||||
if obs.BarometricPressurePa == nil {
|
||||
t.Fatalf("BarometricPressurePa = nil, want non-nil")
|
||||
}
|
||||
if got, want := *obs.BarometricPressurePa, 101600.0; got != want {
|
||||
t.Fatalf("BarometricPressurePa = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildObservationPressureFallbackToSurface(t *testing.T) {
|
||||
surfacePressure := 1008.0
|
||||
|
||||
parsed := omResponse{
|
||||
Timezone: "UTC",
|
||||
UTCOffsetSeconds: 0,
|
||||
Current: omCurrent{
|
||||
Time: "2026-03-16T19:00",
|
||||
SurfacePressure: &surfacePressure,
|
||||
},
|
||||
}
|
||||
|
||||
obs, _, err := buildObservation(parsed)
|
||||
if err != nil {
|
||||
t.Fatalf("buildObservation() error = %v", err)
|
||||
}
|
||||
|
||||
if obs.BarometricPressurePa == nil {
|
||||
t.Fatalf("BarometricPressurePa = nil, want non-nil")
|
||||
}
|
||||
if got, want := *obs.BarometricPressurePa, 100800.0; got != want {
|
||||
t.Fatalf("BarometricPressurePa = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user