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
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -33,6 +33,7 @@ func mapAlertRow(row alertRow) indexedAlert {
|
||||
Sent: timePtr(row.Sent),
|
||||
Effective: timePtr(row.Effective),
|
||||
Onset: timePtr(row.Onset),
|
||||
Ends: timePtr(row.Ends),
|
||||
Expires: timePtr(row.Expires),
|
||||
AreaDescription: stringValue(row.AreaDescription),
|
||||
SenderName: stringValue(row.SenderName),
|
||||
|
||||
@@ -33,6 +33,7 @@ SELECT
|
||||
sent,
|
||||
effective,
|
||||
onset,
|
||||
ends,
|
||||
expires,
|
||||
area_description,
|
||||
sender_name
|
||||
|
||||
@@ -70,6 +70,7 @@ func (r *Repository) loadAlerts(ctx context.Context, eventID string) ([]model.We
|
||||
&row.Sent,
|
||||
&row.Effective,
|
||||
&row.Onset,
|
||||
&row.Ends,
|
||||
&row.Expires,
|
||||
&row.AreaDescription,
|
||||
&row.SenderName,
|
||||
|
||||
@@ -35,6 +35,7 @@ type alertRow struct {
|
||||
Sent sql.NullTime
|
||||
Effective sql.NullTime
|
||||
Onset sql.NullTime
|
||||
Ends sql.NullTime
|
||||
Expires sql.NullTime
|
||||
AreaDescription sql.NullString
|
||||
SenderName sql.NullString
|
||||
|
||||
@@ -246,6 +246,36 @@ func TestAttachAlertReferencesPreservesOrder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapAlertRowMapsEndsAndExpires(t *testing.T) {
|
||||
ends := time.Date(2026, 6, 16, 14, 0, 0, 0, time.FixedZone("CDT", -5*3600))
|
||||
expires := time.Date(2026, 6, 16, 11, 0, 0, 0, time.FixedZone("CDT", -5*3600))
|
||||
|
||||
alert := mapAlertRow(alertRow{
|
||||
AlertIndex: 1,
|
||||
AlertID: "alert-1",
|
||||
Ends: sql.NullTime{Time: ends, Valid: true},
|
||||
Expires: sql.NullTime{Time: expires, Valid: true},
|
||||
}).Alert
|
||||
|
||||
if alert.Ends == nil || alert.Ends.Location().String() != "UTC" || !alert.Ends.Equal(ends.UTC()) {
|
||||
t.Fatalf("expected ends UTC %s, got %v", ends.UTC(), alert.Ends)
|
||||
}
|
||||
if alert.Expires == nil || alert.Expires.Location().String() != "UTC" || !alert.Expires.Equal(expires.UTC()) {
|
||||
t.Fatalf("expected expires UTC %s, got %v", expires.UTC(), alert.Expires)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapAlertRowNullableEnds(t *testing.T) {
|
||||
alert := mapAlertRow(alertRow{
|
||||
AlertIndex: 1,
|
||||
AlertID: "alert-1",
|
||||
}).Alert
|
||||
|
||||
if alert.Ends != nil {
|
||||
t.Fatalf("expected nil ends, got %v", alert.Ends)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapCurrentConditionsRowNoSamplesReturnsNil(t *testing.T) {
|
||||
got := mapCurrentConditionsRow(currentConditionsRow{
|
||||
SampleCount: 0,
|
||||
|
||||
Reference in New Issue
Block a user