All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
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)
|
|
}
|
|
}
|