diff --git a/glide.lock b/glide.lock index db1f821..1629e4a 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ hash: 5f6a20dfcbd0d3f8669061128596d7b554934928a05f38a7e8d385c9c78b82d8 -updated: 2020-02-05T16:49:48.973286-05:00 +updated: 2020-02-08T01:01:00.237797-05:00 imports: - name: github.com/sirupsen/logrus version: 3e01752db0189b9157070a0e1668a620f9a85da2 @@ -12,4 +12,6 @@ imports: subpackages: - unix - windows -testImports: [] +testImports: +- name: github.com/kelseyhightower/envconfig + version: 0b417c4ec4a8a82eecc22a1459a504aa55163d61 diff --git a/settings.go b/settings.go index ec24c46..70242c2 100644 --- a/settings.go +++ b/settings.go @@ -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. diff --git a/settings_test.go b/settings_test.go index f75db06..21a1546 100644 --- a/settings_test.go +++ b/settings_test.go @@ -2,7 +2,10 @@ package stats import ( "os" + "reflect" "testing" + + "github.com/kelseyhightower/envconfig" ) func testSetenv(t *testing.T, pairs ...string) (reset func()) { @@ -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) }) @@ -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", "",