Made forecast-period conditionCode optional
All checks were successful
ci/woodpecker/manual/build-image Pipeline was successful
All checks were successful
ci/woodpecker/manual/build-image Pipeline was successful
This commit is contained in:
@@ -101,7 +101,7 @@
|
||||
// - end_time TIMESTAMPTZ -> payload.periods[i].endTime
|
||||
// - name TEXT NULL -> payload.periods[i].name
|
||||
// - is_day BOOLEAN NULL -> payload.periods[i].isDay
|
||||
// - condition_code INTEGER -> payload.periods[i].conditionCode
|
||||
// - condition_code INTEGER NULL -> payload.periods[i].conditionCode
|
||||
// - text_description TEXT NULL -> payload.periods[i].textDescription
|
||||
// - temperature_c DOUBLE PRECISION NULL -> payload.periods[i].temperatureC
|
||||
// - temperature_c_min DOUBLE PRECISION NULL -> payload.periods[i].temperatureCMin
|
||||
|
||||
@@ -137,7 +137,7 @@ func mapForecastEvent(e fkevent.Event) ([]fksinks.PostgresWrite, error) {
|
||||
"end_time": p.EndTime.UTC(),
|
||||
"name": nullableString(p.Name),
|
||||
"is_day": nullableBool(p.IsDay),
|
||||
"condition_code": int(p.ConditionCode),
|
||||
"condition_code": nullableWMOCode(p.ConditionCode),
|
||||
"text_description": nullableString(p.TextDescription),
|
||||
"temperature_c": nullableFloat64(p.TemperatureC),
|
||||
"temperature_c_min": nullableFloat64(p.TemperatureCMin),
|
||||
@@ -370,6 +370,13 @@ func nullableTime(v *time.Time) any {
|
||||
return v.UTC()
|
||||
}
|
||||
|
||||
func nullableWMOCode(v *model.WMOCode) any {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
return int(*v)
|
||||
}
|
||||
|
||||
func compactJSONText(v any) (any, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
|
||||
@@ -63,13 +63,13 @@ func TestMapPostgresEventForecastStructPayload(t *testing.T) {
|
||||
StartTime: time.Date(2026, 3, 16, 19, 0, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2026, 3, 16, 20, 0, 0, 0, time.UTC),
|
||||
IsDay: &isDay,
|
||||
ConditionCode: model.WMOCode(2),
|
||||
ConditionCode: wmoCodePtr(model.WMOCode(2)),
|
||||
TemperatureC: &temp,
|
||||
},
|
||||
{
|
||||
StartTime: time.Date(2026, 3, 16, 20, 0, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2026, 3, 16, 21, 0, 0, 0, time.UTC),
|
||||
ConditionCode: model.WMOCode(3),
|
||||
ConditionCode: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -94,6 +94,9 @@ func TestMapPostgresEventForecastStructPayload(t *testing.T) {
|
||||
if got := writes[1].Values["period_index"]; got != 0 {
|
||||
t.Fatalf("first period index = %#v, want 0", got)
|
||||
}
|
||||
if got := writes[2].Values["condition_code"]; got != nil {
|
||||
t.Fatalf("second period condition_code = %#v, want nil", got)
|
||||
}
|
||||
|
||||
assertAllWritesIncludeAllColumns(t, writes)
|
||||
}
|
||||
@@ -198,7 +201,7 @@ func TestMapPostgresEventMapPayload(t *testing.T) {
|
||||
{
|
||||
StartTime: time.Date(2026, 3, 16, 19, 0, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2026, 3, 16, 20, 0, 0, 0, time.UTC),
|
||||
ConditionCode: model.WMOCode(2),
|
||||
ConditionCode: wmoCodePtr(model.WMOCode(2)),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -299,3 +302,8 @@ func tableColumnCounts() map[string]int {
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func wmoCodePtr(v model.WMOCode) *model.WMOCode {
|
||||
out := v
|
||||
return &out
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ func PostgresSchema() fksinks.PostgresSchema {
|
||||
{Name: "end_time", Type: "TIMESTAMPTZ", Nullable: false},
|
||||
{Name: "name", Type: "TEXT", Nullable: true},
|
||||
{Name: "is_day", Type: "BOOLEAN", Nullable: true},
|
||||
{Name: "condition_code", Type: "INTEGER", Nullable: false},
|
||||
{Name: "condition_code", Type: "INTEGER", Nullable: true},
|
||||
{Name: "text_description", Type: "TEXT", Nullable: true},
|
||||
{Name: "temperature_c", Type: "DOUBLE PRECISION", Nullable: true},
|
||||
{Name: "temperature_c_min", Type: "DOUBLE PRECISION", Nullable: true},
|
||||
|
||||
Reference in New Issue
Block a user