Update to support upstream weatherfeeder v0.12.1 and add ends field to the alerts schema
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful

This commit is contained in:
2026-06-16 20:08:03 -05:00
parent f4dd701204
commit 2a33fe01cf
15 changed files with 117 additions and 36 deletions

View File

@@ -324,12 +324,14 @@ func TestObservationUSUnitsChangesFieldNames(t *testing.T) {
}
func TestAlertsUSUnitsKeepSchema(t *testing.T) {
ends := time.Date(2026, 6, 11, 14, 0, 0, 0, time.UTC)
h := newHandler(t, &fakeService{
alerts: &model.WeatherAlertRun{
AsOf: time.Now().UTC(),
Alerts: []model.WeatherAlert{{
ID: "abc",
Headline: "A headline",
Ends: &ends,
}},
},
}, "/alerts/active")
@@ -359,6 +361,9 @@ func TestAlertsUSUnitsKeepSchema(t *testing.T) {
if first["id"] != "abc" {
t.Fatalf("expected alert id abc, got %#v", first["id"])
}
if _, ok := first["ends"].(string); !ok {
t.Fatalf("expected alert ends string, got %#v", first["ends"])
}
}
func TestAlertsRouteRegistered(t *testing.T) {
@@ -456,8 +461,10 @@ func TestAlertsTextOmitsInactiveAlertsAfterServiceFiltering(t *testing.T) {
activeAt := time.Date(2026, 6, 11, 12, 0, 0, 0, time.UTC)
setAlertNowForTest(t, activeAt)
effective := activeAt.Add(-1 * time.Hour)
activeExpires := activeAt.Add(1 * time.Hour)
expiredAtBoundary := activeAt
activeEnds := activeAt.Add(1 * time.Hour)
expiredEndsAtBoundary := activeAt
expiredProviderMetadata := activeAt.Add(-30 * time.Minute)
activeProviderMetadata := activeAt.Add(30 * time.Minute)
repo := &alertRepository{
alerts: &model.WeatherAlertRun{
AsOf: activeAt,
@@ -467,21 +474,23 @@ func TestAlertsTextOmitsInactiveAlertsAfterServiceFiltering(t *testing.T) {
Headline: "Active warning",
MessageType: "Alert",
Effective: &effective,
Expires: &activeExpires,
Ends: &activeEnds,
Expires: &expiredProviderMetadata,
},
{
ID: "expired-alert",
Headline: "Expired warning",
MessageType: "Alert",
Effective: &effective,
Expires: &expiredAtBoundary,
Ends: &expiredEndsAtBoundary,
Expires: &activeProviderMetadata,
},
{
ID: "canceled-alert",
Headline: "Canceled warning",
MessageType: " cancel ",
Effective: &effective,
Expires: &activeExpires,
Ends: &activeEnds,
},
},
},
@@ -496,7 +505,7 @@ func TestAlertsTextOmitsInactiveAlertsAfterServiceFiltering(t *testing.T) {
t.Fatalf("expected 200, got %d", w.Code)
}
body := w.Body.String()
for _, want := range []string{"Alerts: 1", "active-alert", "Active warning"} {
for _, want := range []string{"Alerts: 1", "active-alert", "Active warning", "Ends:"} {
if !strings.Contains(body, want) {
t.Fatalf("expected %q in text body, got %q", want, body)
}
@@ -2448,7 +2457,7 @@ func testRenderers(t *testing.T) *render.Registry {
"outlooks_convective.txt.tmpl": "Convective Outlook\n{{if .Data}}Outlooks: {{len .Data.Outlooks}}\nDiscussions: {{len .Data.Discussions}}{{range .Data.Discussions}}\nDiscussion: {{.Discussion}}{{end}}{{else}}No convective outlook data available.{{end}}",
"weatherstories.txt.tmpl": "Weather Stories",
"weatherstories_latest.txt.tmpl": "Latest Weather Story",
"alerts_active.txt.tmpl": "{{if .Data}}Active Alerts\nAlerts: {{len .Data.Alerts}}{{range .Data.Alerts}}\n{{.ID}}{{if .Headline}}\nHeadline: {{.Headline}}{{end}}{{end}}{{else}}No active alerts data available.{{end}}",
"alerts_active.txt.tmpl": "{{if .Data}}Active Alerts\nAlerts: {{len .Data.Alerts}}{{range .Data.Alerts}}\n{{.ID}}{{if .Headline}}\nHeadline: {{.Headline}}{{end}}{{if .Ends}}\nEnds: {{.Ends}}{{end}}{{end}}{{else}}No active alerts data available.{{end}}",
"conditions_current.txt.tmpl": "Conditions text",
} {
tmpl, err := template.New(name).Parse(body)