metrics/config_test.go
Dmytro Kozlov 42c28a8486
support push config for InitPush (#53)
PushConfig represents a struct package uses for pushing
metrics to remote destination. Having a structure
helps to extend functionality in the future, without
touching the signature of existing functions.

For example, `PushConfig` supports custom HTTP headers
via `Headers` param.

Updates https://github.com/VictoriaMetrics/metrics/issues/52
Updates https://github.com/VictoriaMetrics/metrics/issues/36 

Co-authored-by: hagen1778 <roman@victoriametrics.com>
2023-12-15 13:08:55 +01:00

34 lines
954 B
Go

package metrics
import (
"testing"
"time"
)
func TestPushConfigValidateError(t *testing.T) {
f := func(config *PushConfig) {
t.Helper()
if err := config.Validate(); err == nil {
t.Fatalf("expecting non-nil error when validating %v", config)
}
}
f(&PushConfig{})
f(&PushConfig{URL: "", Interval: time.Second})
f(&PushConfig{URL: "https://localhost:8080", Interval: -1 * time.Second})
f(&PushConfig{URL: "htt://localhost:8080", Interval: time.Second})
f(&PushConfig{URL: "http://localhost:8080", Interval: time.Second, ExtraLabels: "a{} "})
}
func TestPushConfigValidateSuccess(t *testing.T) {
f := func(config *PushConfig) {
t.Helper()
if err := config.Validate(); err != nil {
t.Fatalf("expecting nil error when validating %v; err: %s", config, err)
}
}
f(&PushConfig{URL: "http://localhost:8080", Interval: time.Second})
f(&PushConfig{URL: "http://localhost:8080", Interval: time.Second, ExtraLabels: `foo="bar"`})
}