Update default timezone, dayparts, and related tests

This commit is contained in:
2026-05-29 19:22:02 -05:00
parent 1bc0739d31
commit 26e6f33cde
7 changed files with 29 additions and 23 deletions

3
.gitignore vendored
View File

@@ -1,5 +1,6 @@
# Compiled application binary # Compiled application binary and testing workspace
/weatherreporter /weatherreporter
/workspace
# ---> Go # ---> Go
# If you prefer the allow list template instead of the deny list, see community template: # If you prefer the allow list template instead of the deny list, see community template:

View File

@@ -45,7 +45,7 @@ config test suite.
- `timeout`: HTTP timeout duration. Default: `10s`. - `timeout`: HTTP timeout duration. Default: `10s`.
- `precision`: numeric precision query value. Default: `1`. - `precision`: numeric precision query value. Default: `1`.
- `units`: Weather API units query value. Default: `us`. - `units`: Weather API units query value. Default: `us`.
- `timezone`: report timezone and Weather API timezone query value where supported. Default: `Chicago`. - `timezone`: report timezone and Weather API timezone query value where supported. Default: `America/Chicago`.
- `format`: Weather API response format. Must be `json`. Default: `json`. - `format`: Weather API response format. Must be `json`. Default: `json`.
Timezone values may be IANA names, configured aliases such as `Chicago` and Timezone values may be IANA names, configured aliases such as `Chicago` and
@@ -88,7 +88,7 @@ Each entry has:
- `end` - `end`
`start` and `end` use `HH:MM`. The default entries are overnight, morning, `start` and `end` use `HH:MM`. The default entries are overnight, morning,
afternoon, and evening. midday, afternoon, and evening.
### `recent_change` ### `recent_change`

View File

@@ -1,9 +1,9 @@
weather_api: weather_api:
base_url: https://weather.api.example.com/ base_url: https://weather.api.rakestrawhome.com/
timeout: 15s timeout: 15s
precision: 1 precision: 1
units: us units: us
timezone: Chicago timezone: "America/Chicago"
format: json format: json
missing_source: missing_source:
@@ -28,12 +28,15 @@ dayparts:
end: "06:00" end: "06:00"
- name: morning - name: morning
start: "06:00" start: "06:00"
end: "12:00" end: "10:00"
- name: midday
start: "10:00"
end: "15:00"
- name: afternoon - name: afternoon
start: "12:00" start: "15:00"
end: "18:00" end: "17:00"
- name: evening - name: evening
start: "18:00" start: "17:00"
end: "24:00" end: "24:00"
recent_change: recent_change:

View File

@@ -72,7 +72,7 @@ func TestFetchBundleBuildsExpectedQueries(t *testing.T) {
t.Fatalf("request %q missing format=json or units=us", rawURL) t.Fatalf("request %q missing format=json or units=us", rawURL)
} }
if strings.HasPrefix(rawURL, "/forecast/") { if strings.HasPrefix(rawURL, "/forecast/") {
if !strings.Contains(rawURL, "precision=1") || !strings.Contains(rawURL, "tz=Chicago") { if !strings.Contains(rawURL, "precision=1") || !strings.Contains(rawURL, "tz=America%2FChicago") {
t.Fatalf("forecast request %q missing precision or tz", rawURL) t.Fatalf("forecast request %q missing precision or tz", rawURL)
} }
} }

View File

@@ -55,8 +55,8 @@ func TestDailyBriefingFromRepresentativeFixture(t *testing.T) {
if pkg.Daily == nil { if pkg.Daily == nil {
t.Fatal("Daily = nil") t.Fatal("Daily = nil")
} }
if len(pkg.Daily.Dayparts) != 4 { if len(pkg.Daily.Dayparts) != 5 {
t.Fatalf("Dayparts length = %d, want 4", len(pkg.Daily.Dayparts)) t.Fatalf("Dayparts length = %d, want 5", len(pkg.Daily.Dayparts))
} }
if len(pkg.Daily.RelevantAlerts) != 1 { if len(pkg.Daily.RelevantAlerts) != 1 {
t.Fatalf("RelevantAlerts length = %d, want 1", len(pkg.Daily.RelevantAlerts)) t.Fatalf("RelevantAlerts length = %d, want 1", len(pkg.Daily.RelevantAlerts))
@@ -237,9 +237,10 @@ func mustResolveDaily(t *testing.T, location *time.Location) report.Resolved {
func defaultDayparts() []forecast.DaypartDefinition { func defaultDayparts() []forecast.DaypartDefinition {
return []forecast.DaypartDefinition{ return []forecast.DaypartDefinition{
{Name: "overnight", Start: "00:00", End: "06:00"}, {Name: "overnight", Start: "00:00", End: "06:00"},
{Name: "morning", Start: "06:00", End: "12:00"}, {Name: "morning", Start: "06:00", End: "10:00"},
{Name: "afternoon", Start: "12:00", End: "18:00"}, {Name: "midday", Start: "10:00", End: "15:00"},
{Name: "evening", Start: "18:00", End: "24:00"}, {Name: "afternoon", Start: "15:00", End: "17:00"},
{Name: "evening", Start: "17:00", End: "24:00"},
} }
} }

View File

@@ -17,8 +17,8 @@ func TestDefaults(t *testing.T) {
if cfg.WeatherAPI.Units != "us" { if cfg.WeatherAPI.Units != "us" {
t.Fatalf("Units = %q, want us", cfg.WeatherAPI.Units) t.Fatalf("Units = %q, want us", cfg.WeatherAPI.Units)
} }
if cfg.WeatherAPI.Timezone != "Chicago" { if cfg.WeatherAPI.Timezone != "America/Chicago" {
t.Fatalf("Timezone = %q, want Chicago", cfg.WeatherAPI.Timezone) t.Fatalf("Timezone = %q, want America/Chicago", cfg.WeatherAPI.Timezone)
} }
if cfg.WeatherAPI.Format != "json" { if cfg.WeatherAPI.Format != "json" {
t.Fatalf("Format = %q, want json", cfg.WeatherAPI.Format) t.Fatalf("Format = %q, want json", cfg.WeatherAPI.Format)
@@ -34,8 +34,8 @@ func TestLoadExampleConfig(t *testing.T) {
t.Fatalf("LoadFile() error = %v", err) t.Fatalf("LoadFile() error = %v", err)
} }
if cfg.WeatherAPI.BaseURL != "https://weather.api.example.com/" { if cfg.WeatherAPI.BaseURL != "https://weather.api.rakestrawhome.com/" {
t.Fatalf("BaseURL = %q, want example URL", cfg.WeatherAPI.BaseURL) t.Fatalf("BaseURL = %q, want configured example URL", cfg.WeatherAPI.BaseURL)
} }
if cfg.WeatherAPI.Timeout != 15*time.Second { if cfg.WeatherAPI.Timeout != 15*time.Second {
t.Fatalf("Timeout = %s, want 15s", cfg.WeatherAPI.Timeout) t.Fatalf("Timeout = %s, want 15s", cfg.WeatherAPI.Timeout)

View File

@@ -10,7 +10,7 @@ func Defaults() Config {
Timeout: 10 * time.Second, Timeout: 10 * time.Second,
Precision: 1, Precision: 1,
Units: "us", Units: "us",
Timezone: "Chicago", Timezone: "America/Chicago",
Format: "json", Format: "json",
}, },
MissingSource: MissingSourceConfig{ MissingSource: MissingSourceConfig{
@@ -30,9 +30,10 @@ func Defaults() Config {
}, },
Dayparts: []DaypartConfig{ Dayparts: []DaypartConfig{
{Name: "overnight", Start: "00:00", End: "06:00"}, {Name: "overnight", Start: "00:00", End: "06:00"},
{Name: "morning", Start: "06:00", End: "12:00"}, {Name: "morning", Start: "06:00", End: "10:00"},
{Name: "afternoon", Start: "12:00", End: "18:00"}, {Name: "midday", Start: "10:00", End: "15:00"},
{Name: "evening", Start: "18:00", End: "24:00"}, {Name: "afternoon", Start: "15:00", End: "17:00"},
{Name: "evening", Start: "17:00", End: "24:00"},
}, },
RecentChange: RecentChangeConfig{ RecentChange: RecentChangeConfig{
TemperatureDegrees: 5, TemperatureDegrees: 5,