File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ func NewConfiguration(path string) (*Configuration, error) {
5656 v .AddConfigPath ("." )
5757 v .AddConfigPath ("$HOME" )
5858
59+ v .SetDefault ("Token" , "" )
5960 v .SetDefault ("CheckPeriod" , 5 * time .Minute )
6061 v .SetDefault ("RequestTimeout" , 10 * time .Second )
6162 v .SetDefault ("IPv6" , false )
Original file line number Diff line number Diff line change 55 "os"
66 "strings"
77 "testing"
8+ "time"
89
910 "github.com/matryer/is"
1011)
@@ -102,3 +103,29 @@ domains:
102103 _ , err = NewConfiguration (fname )
103104 is .True (strings .Contains (err .Error (), "records can't be empty" ))
104105}
106+
107+ func TestEnvVarsAreRead (t * testing.T ) {
108+
109+ is := is .New (t )
110+ fname , rm := createTmpFile (t )
111+ defer rm ()
112+
113+ err := ioutil .WriteFile (fname , []byte (`domains:
114+ example.com:
115+ - type: A
116+ name: www` ), 0644 )
117+
118+ is .NoErr (err )
119+
120+ os .Setenv ("DDNS_TOKEN" , "abc" )
121+ os .Setenv ("DDNS_CHECKPERIOD" , "60s" )
122+ os .Setenv ("DDNS_REQUESTTIMEOUT" , "12s" )
123+ os .Setenv ("DDNS_IPV6" , "true" )
124+ conf , err := NewConfiguration (fname )
125+ is .NoErr (err )
126+
127+ is .Equal ("abc" , conf .Token )
128+ is .Equal (60 * time .Second , conf .CheckPeriod )
129+ is .Equal (12 * time .Second , conf .RequestTimeout )
130+ is .Equal (true , conf .IPv6 )
131+ }
You can’t perform that action at this time.
0 commit comments