From 8e99baedf2c3e433750c2f51681f3c9d15d412be Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 14 Feb 2015 11:24:17 +0100 Subject: First version --- nesting_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 nesting_test.go (limited to 'nesting_test.go') 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 @@ +package envcfg + +import ( + "os" + "testing" +) + +type nestedStruct struct { + SubStruct struct { + Field string + } +} + +func TestNestedMapping(t *testing.T) { + const ENV_KEY = "SUBSTRUCT_FIELD" + const ENV_VAL = "Remember: testing is the future!" + + os.Clearenv() + os.Setenv(ENV_KEY, ENV_VAL) + + s := nestedStruct{} + + ReadInto(&s) + + if s.SubStruct.Field != ENV_VAL { + t.Errorf("expected '%s', got '%s'", ENV_VAL, s.SubStruct.Field) + } +} + +type deeplyNestedStruct struct { + SubStruct struct { + SubSubStruct struct { + Field string + } + } +} + +func TestDeeplyNestedMapping(t *testing.T) { + const ENV_KEY = "SUBSTRUCT_SUBSUBSTRUCT_FIELD" + const ENV_VAL = "Remember: testing is the future!" + + os.Clearenv() + os.Setenv(ENV_KEY, ENV_VAL) + + s := deeplyNestedStruct{} + + ReadInto(&s) + + if s.SubStruct.SubSubStruct.Field != ENV_VAL { + t.Errorf("expected '%s', got '%s'", ENV_VAL, s.SubStruct.SubSubStruct.Field) + } +} -- cgit v1.2.3