diff --git a/conf/conf.go b/conf/conf.go index 179bee3..0f3a1eb 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -56,6 +56,7 @@ func NewConfiguration(path string) (*Configuration, error) { v.AddConfigPath(".") v.AddConfigPath("$HOME") + v.SetDefault("Token", "") v.SetDefault("CheckPeriod", 5*time.Minute) v.SetDefault("RequestTimeout", 10*time.Second) v.SetDefault("IPv6", false) diff --git a/conf/conf_test.go b/conf/conf_test.go index a6c57cb..df4de80 100644 --- a/conf/conf_test.go +++ b/conf/conf_test.go @@ -5,6 +5,7 @@ import ( "os" "strings" "testing" + "time" "github.com/matryer/is" ) @@ -102,3 +103,29 @@ domains: _, err = NewConfiguration(fname) is.True(strings.Contains(err.Error(), "records can't be empty")) } + +func TestEnvVarsAreRead(t *testing.T) { + + is := is.New(t) + fname, rm := createTmpFile(t) + defer rm() + + err := ioutil.WriteFile(fname, []byte(`domains: + example.com: + - type: A + name: www`), 0644) + + is.NoErr(err) + + os.Setenv("DDNS_TOKEN", "abc") + os.Setenv("DDNS_CHECKPERIOD", "60s") + os.Setenv("DDNS_REQUESTTIMEOUT", "12s") + os.Setenv("DDNS_IPV6", "true") + conf, err := NewConfiguration(fname) + is.NoErr(err) + + is.Equal("abc", conf.Token) + is.Equal(60*time.Second, conf.CheckPeriod) + is.Equal(12*time.Second, conf.RequestTimeout) + is.Equal(true, conf.IPv6) +}