Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings: set DefaultUseStatsd to true #89

Merged
merged 1 commit into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const (
// DefaultUseStatsd use statsd as a stats sink, default is false.
DefaultUseStatsd = false
// DefaultUseStatsd use statsd as a stats sink, default is true.
DefaultUseStatsd = true
// DefaultStatsdHost is the default address where statsd is running at.
DefaultStatsdHost = "localhost"
// DefaultStatsdPort is the default port where statsd is listening at.
Expand Down
33 changes: 31 additions & 2 deletions settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package stats

import (
"os"
"reflect"
"testing"

"github.com/kelseyhightower/envconfig"
)

func testSetenv(t *testing.T, pairs ...string) (reset func()) {
Expand All @@ -12,8 +15,14 @@ func testSetenv(t *testing.T, pairs ...string) (reset func()) {
val := pairs[i+1]

prev, exists := os.LookupEnv(key)
if err := os.Setenv(key, val); err != nil {
t.Fatalf("setting env key: %s: %s", key, err)
if val == "" {
if err := os.Unsetenv(key); err != nil {
t.Fatalf("deleting env key: %s: %s", key, err)
}
} else {
if err := os.Setenv(key, val); err != nil {
t.Fatalf("setting env key: %s: %s", key, err)
}
}
if exists {
fns = append(fns, func() { os.Setenv(key, prev) })
Expand All @@ -28,6 +37,26 @@ func testSetenv(t *testing.T, pairs ...string) (reset func()) {
}
}

func TestSettingsCompat(t *testing.T) {
reset := testSetenv(t,
"USE_STATSD", "",
"STATSD_HOST", "",
"STATSD_PORT", "",
"GOSTATS_FLUSH_INTERVAL_SECONDS", "",
)
defer reset()

var e Settings
if err := envconfig.Process("", &e); err != nil {
t.Fatal(err)
}

s := GetSettings()
if !reflect.DeepEqual(e, s) {
t.Fatalf("Default Settings: want: %+v got: %+v", e, s)
}
}

func TestSettingsDefault(t *testing.T) {
reset := testSetenv(t,
"USE_STATSD", "",
Expand Down