aboutsummaryrefslogtreecommitdiff
path: root/nesting_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'nesting_test.go')
-rw-r--r--nesting_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/nesting_test.go b/nesting_test.go
new file mode 100644
index 0000000..3fcc059
--- /dev/null
+++ b/nesting_test.go
@@ -0,0 +1,52 @@
1package envcfg
2
3import (
4 "os"
5 "testing"
6)
7
8type nestedStruct struct {
9 SubStruct struct {
10 Field string
11 }
12}
13
14func TestNestedMapping(t *testing.T) {
15 const ENV_KEY = "SUBSTRUCT_FIELD"
16 const ENV_VAL = "Remember: testing is the future!"
17
18 os.Clearenv()
19 os.Setenv(ENV_KEY, ENV_VAL)
20
21 s := nestedStruct{}
22
23 ReadInto(&s)
24
25 if s.SubStruct.Field != ENV_VAL {
26 t.Errorf("expected '%s', got '%s'", ENV_VAL, s.SubStruct.Field)
27 }
28}
29
30type deeplyNestedStruct struct {
31 SubStruct struct {
32 SubSubStruct struct {
33 Field string
34 }
35 }
36}
37
38func TestDeeplyNestedMapping(t *testing.T) {
39 const ENV_KEY = "SUBSTRUCT_SUBSUBSTRUCT_FIELD"
40 const ENV_VAL = "Remember: testing is the future!"
41
42 os.Clearenv()
43 os.Setenv(ENV_KEY, ENV_VAL)
44
45 s := deeplyNestedStruct{}
46
47 ReadInto(&s)
48
49 if s.SubStruct.SubSubStruct.Field != ENV_VAL {
50 t.Errorf("expected '%s', got '%s'", ENV_VAL, s.SubStruct.SubSubStruct.Field)
51 }
52}