Skip to content

Commit

Permalink
Merge pull request #32 from skibish/fix/read-env-variables
Browse files Browse the repository at this point in the history
fix: read ddns_token env var
  • Loading branch information
skibish authored Jun 5, 2022
2 parents fbeeae0 + f61b206 commit 2ce9d16
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 2ce9d16

Please sign in to comment.