1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-26 18:21:01 +00:00

refactor(metric): use time.Duration for refresh duration

This commit is contained in:
gudvinr 2025-08-18 23:10:18 +03:00 committed by Frédéric Guillot
parent c6536e8d90
commit 4af12a4129
4 changed files with 64 additions and 9 deletions

View file

@ -2230,3 +2230,58 @@ func TestCustomPollingLimitPerHost(t *testing.T) {
t.Fatalf(`Unexpected custom PollingLimitPerHost value, got %v instead of %v`, result, expected)
}
}
func TestMetricsRefreshInterval(t *testing.T) {
os.Clearenv()
os.Setenv("METRICS_REFRESH_INTERVAL", "33")
parser := NewParser()
opts, err := parser.ParseEnvironmentVariables()
if err != nil {
t.Fatalf(`Parsing failure: %v`, err)
}
expected := 33 * time.Second
result := opts.MetricsRefreshInterval()
if result != expected {
t.Fatalf(`Unexpected METRICS_REFRESH_INTERVAL value, got %d instead of %d`, result, expected)
}
sorted := opts.SortedOptions(false)
i := slices.IndexFunc(sorted, func(opt *option) bool {
return opt.Key == "METRICS_REFRESH_INTERVAL"
})
expectedSerialized := 33
if got := sorted[i].Value; got != expectedSerialized {
t.Fatalf(`Unexpected value in option output, got %q instead of %q`, got, expectedSerialized)
}
}
func TestDefaultMetricsRefreshInterval(t *testing.T) {
os.Clearenv()
parser := NewParser()
opts, err := parser.ParseEnvironmentVariables()
if err != nil {
t.Fatalf(`Parsing failure: %v`, err)
}
expected := defaultMetricsRefreshInterval
result := opts.MetricsRefreshInterval()
if result != expected {
t.Fatalf(`Unexpected METRICS_REFRESH_INTERVAL value, got %d instead of %d`, result, expected)
}
sorted := opts.SortedOptions(false)
i := slices.IndexFunc(sorted, func(opt *option) bool {
return opt.Key == "METRICS_REFRESH_INTERVAL"
})
expectedSerialized := int(defaultMetricsRefreshInterval / time.Second)
if got := sorted[i].Value; got != expectedSerialized {
t.Fatalf(`Unexpected value in option output, got %q instead of %q`, got, expectedSerialized)
}
}