-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoenv_test.go
48 lines (37 loc) · 1.12 KB
/
goenv_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package goconf_test
import (
"testing"
"github.com/bdrbt/goconf"
)
func TestLoadEnv(t *testing.T) {
type TestConf struct {
String string `env:"SIMPLE_STRING"`
Integer int `env:"INT_VALUE"`
Boolean bool `env:"BOOLEAN_VALUE"`
DefaultString string `env:"DEFAULT_STRING" default:"default string"`
UnqottedString string `env:"QUOTTED_STRING"`
}
var tc TestConf
t.Setenv("SIMPLE_STRING", "simple")
t.Setenv("INT_VALUE", "42")
t.Setenv("BOOLEAN_VALUE", "true")
t.Setenv("QUOTTED_STRING", "\"noquotes\"")
if err := goconf.LoadEnv(&tc); err != nil {
t.Error("Error while loading environment: ", err)
}
if tc.String != "simple" {
t.Error("String vaue is not set")
}
if tc.Integer != 42 {
t.Errorf("Integer vaue is not set, want:%d got:%d", 42, tc.Integer)
}
if tc.Boolean != true {
t.Errorf("Boolean vaue is not set, want: %t got:%t", true, tc.Boolean)
}
if tc.DefaultString != "default string" {
t.Errorf("Fafault string not set to declared default value")
}
if tc.UnqottedString != "noquotes" {
t.Errorf("Quotes not removed, want: noquotes got:%s", tc.UnqottedString)
}
}