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:
58
internal/normalizers/openweather/observation_test.go
Normal file
58
internal/normalizers/openweather/observation_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package openweather
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBuildObservationTextDescriptionAndPressurePrecedence(t *testing.T) {
|
||||
seaLevel := 1018.0
|
||||
|
||||
parsed := owmResponse{}
|
||||
parsed.Dt = 1710000000
|
||||
parsed.Main.Temp = 20.0
|
||||
parsed.Main.Humidity = 45.0
|
||||
parsed.Main.Pressure = 1000.0
|
||||
parsed.Main.SeaLevel = &seaLevel
|
||||
parsed.Wind.Speed = 3.0
|
||||
parsed.Weather = []owmWeather{
|
||||
{ID: 801, Main: "Clouds", Description: "few clouds", Icon: "02d"},
|
||||
}
|
||||
|
||||
obs, _, err := buildObservation(parsed)
|
||||
if err != nil {
|
||||
t.Fatalf("buildObservation() error = %v", err)
|
||||
}
|
||||
|
||||
if obs.TextDescription != "few clouds" {
|
||||
t.Fatalf("TextDescription = %q, want %q", obs.TextDescription, "few clouds")
|
||||
}
|
||||
|
||||
if obs.BarometricPressurePa == nil {
|
||||
t.Fatalf("BarometricPressurePa = nil, want non-nil")
|
||||
}
|
||||
if got, want := *obs.BarometricPressurePa, 101800.0; got != want {
|
||||
t.Fatalf("BarometricPressurePa = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildObservationPressureFallbackToSurface(t *testing.T) {
|
||||
parsed := owmResponse{}
|
||||
parsed.Dt = 1710000000
|
||||
parsed.Main.Temp = 20.0
|
||||
parsed.Main.Humidity = 45.0
|
||||
parsed.Main.Pressure = 1001.0
|
||||
parsed.Wind.Speed = 3.0
|
||||
parsed.Weather = []owmWeather{
|
||||
{ID: 800, Description: "clear sky", Icon: "01d"},
|
||||
}
|
||||
|
||||
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, 100100.0; got != want {
|
||||
t.Fatalf("BarometricPressurePa = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user