Centralize weather event and driver identifiers

This commit is contained in:
2026-06-11 02:08:36 +00:00
parent dec05821bf
commit b7277e0c02
31 changed files with 162 additions and 119 deletions

View File

@@ -6,13 +6,17 @@ import (
"gitea.maximumdirect.net/ejr/feedkit/config"
fksource "gitea.maximumdirect.net/ejr/feedkit/sources"
"gitea.maximumdirect.net/ejr/weatherfeeder/internal/sources/nws"
"gitea.maximumdirect.net/ejr/weatherfeeder/internal/sources/openmeteo"
"gitea.maximumdirect.net/ejr/weatherfeeder/internal/sources/openweather"
"gitea.maximumdirect.net/ejr/weatherfeeder/internal/sources/spc"
)
func TestRegisterBuiltinsRegistersNWSHourlyForecastDriver(t *testing.T) {
reg := fksource.NewRegistry()
RegisterBuiltins(reg)
in, err := reg.BuildInput(sourceConfigForDriver("nws_forecast_hourly"))
in, err := reg.BuildInput(sourceConfigForDriver(nws.DriverForecastHourly))
if err != nil {
t.Fatalf("BuildInput(nws_forecast_hourly) error = %v", err)
}
@@ -25,7 +29,7 @@ func TestRegisterBuiltinsRegistersNWSNarrativeForecastDriver(t *testing.T) {
reg := fksource.NewRegistry()
RegisterBuiltins(reg)
in, err := reg.BuildInput(sourceConfigForDriver("nws_forecast_narrative"))
in, err := reg.BuildInput(sourceConfigForDriver(nws.DriverForecastNarrative))
if err != nil {
t.Fatalf("BuildInput(nws_forecast_narrative) error = %v", err)
}
@@ -38,7 +42,7 @@ func TestRegisterBuiltinsRegistersNWSForecastDiscussionDriver(t *testing.T) {
reg := fksource.NewRegistry()
RegisterBuiltins(reg)
in, err := reg.BuildInput(sourceConfigForDriver("nws_forecast_discussion"))
in, err := reg.BuildInput(sourceConfigForDriver(nws.DriverForecastDiscussion))
if err != nil {
t.Fatalf("BuildInput(nws_forecast_discussion) error = %v", err)
}
@@ -51,7 +55,7 @@ func TestRegisterBuiltinsRegistersNWSWeatherStoriesDriver(t *testing.T) {
reg := fksource.NewRegistry()
RegisterBuiltins(reg)
in, err := reg.BuildInput(sourceConfigForDriver("nws_weatherstories"))
in, err := reg.BuildInput(sourceConfigForDriver(nws.DriverWeatherStories))
if err != nil {
t.Fatalf("BuildInput(nws_weatherstories) error = %v", err)
}
@@ -78,16 +82,16 @@ func TestRegisterBuiltinsRegistersAllCurrentDrivers(t *testing.T) {
RegisterBuiltins(reg)
drivers := []string{
"nws_observation",
"nws_alerts",
"nws_forecast_hourly",
"nws_forecast_narrative",
"nws_forecast_discussion",
"nws_weatherstories",
"openmeteo_observation",
"openmeteo_forecast",
"openweather_observation",
"spc_convective_outlook",
nws.DriverObservation,
nws.DriverAlerts,
nws.DriverForecastHourly,
nws.DriverForecastNarrative,
nws.DriverForecastDiscussion,
nws.DriverWeatherStories,
openmeteo.DriverObservation,
openmeteo.DriverForecast,
openweather.DriverObservation,
spc.DriverConvectiveOutlook,
}
for _, driver := range drivers {
@@ -103,14 +107,14 @@ func TestRegisterBuiltinsRegistersAllCurrentDrivers(t *testing.T) {
func sourceConfigForDriver(driver string) config.SourceConfig {
url := "https://example.invalid"
if driver == "openweather_observation" {
if driver == openweather.DriverObservation {
url = "https://example.invalid?units=metric"
}
params := map[string]any{
"url": url,
"user_agent": "test-agent",
}
if driver == "spc_convective_outlook" {
if driver == spc.DriverConvectiveOutlook {
params["latitude"] = 38.6239
params["longitude"] = -90.3571
}