Centralize weather event and driver identifiers
This commit is contained in:
6
internal/sources/openweather/driver.go
Normal file
6
internal/sources/openweather/driver.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package openweather
|
||||
|
||||
// Source driver strings registered by weatherfeeder for OpenWeather sources.
|
||||
const (
|
||||
DriverObservation = "openweather_observation"
|
||||
)
|
||||
@@ -19,9 +19,7 @@ type ObservationSource struct {
|
||||
}
|
||||
|
||||
func NewObservationSource(cfg config.SourceConfig) (*ObservationSource, error) {
|
||||
const driver = "openweather_observation"
|
||||
|
||||
hs, err := fksources.NewHTTPSource(driver, cfg, "application/json")
|
||||
hs, err := fksources.NewHTTPSource(DriverObservation, cfg, "application/json")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -35,7 +33,9 @@ func NewObservationSource(cfg config.SourceConfig) (*ObservationSource, error) {
|
||||
|
||||
func (s *ObservationSource) Name() string { return s.http.Name }
|
||||
|
||||
func (s *ObservationSource) Kinds() []event.Kind { return []event.Kind{event.Kind("observation")} }
|
||||
func (s *ObservationSource) Kinds() []event.Kind {
|
||||
return []event.Kind{event.Kind(standards.KindObservation)}
|
||||
}
|
||||
|
||||
func (s *ObservationSource) Poll(ctx context.Context) ([]event.Event, error) {
|
||||
if err := owcommon.RequireMetricUnits(s.http.URL); err != nil {
|
||||
@@ -60,7 +60,7 @@ func (s *ObservationSource) Poll(ctx context.Context) ([]event.Event, error) {
|
||||
eventID := fksources.DefaultEventID("", s.http.Name, effectiveAt, emittedAt)
|
||||
|
||||
return fksources.SingleEvent(
|
||||
event.Kind("observation"),
|
||||
event.Kind(standards.KindObservation),
|
||||
s.http.Name,
|
||||
standards.SchemaRawOpenWeatherCurrentV1,
|
||||
eventID,
|
||||
|
||||
@@ -5,12 +5,13 @@ import (
|
||||
|
||||
"gitea.maximumdirect.net/ejr/feedkit/config"
|
||||
"gitea.maximumdirect.net/ejr/feedkit/event"
|
||||
"gitea.maximumdirect.net/ejr/weatherfeeder/standards"
|
||||
)
|
||||
|
||||
func TestObservationSourceAdvertisesKinds(t *testing.T) {
|
||||
src, err := NewObservationSource(config.SourceConfig{
|
||||
Name: "openweather-observation-test",
|
||||
Driver: "openweather_observation",
|
||||
Driver: DriverObservation,
|
||||
Mode: config.SourceModePoll,
|
||||
Params: map[string]any{
|
||||
"url": "https://example.invalid?units=metric",
|
||||
@@ -20,7 +21,7 @@ func TestObservationSourceAdvertisesKinds(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("NewObservationSource() error = %v", err)
|
||||
}
|
||||
if got := src.Kinds(); len(got) != 1 || got[0] != event.Kind("observation") {
|
||||
if got := src.Kinds(); len(got) != 1 || got[0] != event.Kind(standards.KindObservation) {
|
||||
t.Fatalf("Kinds() = %#v, want [observation]", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user