Add a /conditions/current endpoint
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:
@@ -110,3 +110,54 @@ func TestAttachAlertReferencesPreservesOrder(t *testing.T) {
|
||||
t.Fatalf("unexpected second alert references: %+v", out[1].References)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapCurrentConditionsRowNoSamplesReturnsNil(t *testing.T) {
|
||||
got := mapCurrentConditionsRow(currentConditionsRow{
|
||||
SampleCount: 0,
|
||||
})
|
||||
if got != nil {
|
||||
t.Fatalf("expected nil for empty sample window, got %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapCurrentConditionsRowMapsFields(t *testing.T) {
|
||||
isDay := true
|
||||
got := mapCurrentConditionsRow(currentConditionsRow{
|
||||
SampleCount: 12,
|
||||
TemperatureC: sql.NullFloat64{Float64: 15.5, Valid: true},
|
||||
ApparentTemperatureC: sql.NullFloat64{Float64: 14.2, Valid: true},
|
||||
DewpointC: sql.NullFloat64{Float64: 10.1, Valid: true},
|
||||
RelativeHumidityPercent: sql.NullFloat64{Float64: 72, Valid: true},
|
||||
WindSpeedKmh: sql.NullFloat64{Float64: 24.8, Valid: true},
|
||||
WindDirectionDegrees: sql.NullFloat64{Float64: 182.5, Valid: true},
|
||||
ConditionCode: sql.NullInt64{Int64: 65, Valid: true},
|
||||
IsDay: sql.NullBool{Bool: isDay, Valid: true},
|
||||
})
|
||||
if got == nil {
|
||||
t.Fatalf("expected mapped current conditions")
|
||||
}
|
||||
if got.TemperatureC == nil || *got.TemperatureC != 15.5 {
|
||||
t.Fatalf("expected temperature pointer 15.5, got %v", got.TemperatureC)
|
||||
}
|
||||
if got.ApparentTemperatureC == nil || *got.ApparentTemperatureC != 14.2 {
|
||||
t.Fatalf("expected apparent temp pointer 14.2, got %v", got.ApparentTemperatureC)
|
||||
}
|
||||
if got.DewpointC == nil || *got.DewpointC != 10.1 {
|
||||
t.Fatalf("expected dewpoint pointer 10.1, got %v", got.DewpointC)
|
||||
}
|
||||
if got.RelativeHumidityPercent == nil || *got.RelativeHumidityPercent != 72 {
|
||||
t.Fatalf("expected rh pointer 72, got %v", got.RelativeHumidityPercent)
|
||||
}
|
||||
if got.WindSpeedKmh == nil || *got.WindSpeedKmh != 24.8 {
|
||||
t.Fatalf("expected wind speed pointer 24.8, got %v", got.WindSpeedKmh)
|
||||
}
|
||||
if got.WindDirectionDegrees == nil || *got.WindDirectionDegrees != 182.5 {
|
||||
t.Fatalf("expected wind direction pointer 182.5, got %v", got.WindDirectionDegrees)
|
||||
}
|
||||
if got.ConditionCode != 65 {
|
||||
t.Fatalf("expected condition code 65, got %d", got.ConditionCode)
|
||||
}
|
||||
if got.IsDay == nil || !*got.IsDay {
|
||||
t.Fatalf("expected isDay pointer true, got %v", got.IsDay)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user