Skip to content

Commit

Permalink
fix: read ddns_token env var
Browse files Browse the repository at this point in the history
Added default value to `DDNS_TOKEN` so that Viper would be able
to find the key and matching env.

More details can be found in spf13/viper#761.

Closes skibish#31
  • Loading branch information
skibish authored and gadgethm committed Jun 5, 2022
1 parent d94ba75 commit ba5451f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions conf/conf.go
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions conf/conf_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"strings"
"testing"
"time"

"github.com/matryer/is"
)
Expand Down Expand Up @@ -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)
}

0 comments on commit ba5451f

Please sign in to comment.