aboutsummaryrefslogtreecommitdiff
path: root/tagging_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tagging_test.go')
-rw-r--r--tagging_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/tagging_test.go b/tagging_test.go
new file mode 100644
index 0000000..2fe2e33
--- /dev/null
+++ b/tagging_test.go
@@ -0,0 +1,70 @@
1package envcfg
2
3import (
4 "os"
5 "testing"
6)
7
8type taggedStruct struct {
9 Field string `env:"CUSTOM_POTATOE"`
10}
11
12func TestTaggedField(t *testing.T) {
13 const ENV_KEY = "CUSTOM_POTATOE"
14 const ENV_VAL = "Remember: testing is the future!"
15
16 os.Clearenv()
17 os.Setenv(ENV_KEY, ENV_VAL)
18
19 s := taggedStruct{}
20
21 ReadInto(&s)
22
23 if s.Field != ENV_VAL {
24 t.Errorf("expected '%s', got '%s'", ENV_VAL, s.Field)
25 }
26}
27
28type taggedSubStruct struct {
29 SubStruct struct {
30 Field string
31 } `env:"POTATOE"`
32}
33
34func TestTaggedSubStruct(t *testing.T) {
35 const ENV_KEY = "POTATOE_FIELD"
36 const ENV_VAL = "Remember: testing is the future!"
37
38 os.Clearenv()
39 os.Setenv(ENV_KEY, ENV_VAL)
40
41 s := taggedSubStruct{}
42
43 ReadInto(&s)
44
45 if s.SubStruct.Field != ENV_VAL {
46 t.Errorf("expected '%s', got '%s'", ENV_VAL, s.SubStruct.Field)
47 }
48}
49
50type absTaggedField struct {
51 SubStruct struct {
52 Field string `env:"POTATOE" absenv:"true"`
53 }
54}
55
56func TestAbsTaggedField(t *testing.T) {
57 const ENV_KEY = "POTATOE"
58 const ENV_VAL = "Remember: testing is the future!"
59
60 os.Clearenv()
61 os.Setenv(ENV_KEY, ENV_VAL)
62
63 s := absTaggedField{}
64
65 ReadInto(&s)
66
67 if s.SubStruct.Field != ENV_VAL {
68 t.Errorf("expected '%s', got '%s'", ENV_VAL, s.SubStruct.Field)
69 }
70}