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 --- tagging_test.go | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tagging_test.go (limited to 'tagging_test.go') 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 @@ +package envcfg + +import ( + "os" + "testing" +) + +type taggedStruct struct { + Field string `env:"CUSTOM_POTATOE"` +} + +func TestTaggedField(t *testing.T) { + const ENV_KEY = "CUSTOM_POTATOE" + const ENV_VAL = "Remember: testing is the future!" + + os.Clearenv() + os.Setenv(ENV_KEY, ENV_VAL) + + s := taggedStruct{} + + ReadInto(&s) + + if s.Field != ENV_VAL { + t.Errorf("expected '%s', got '%s'", ENV_VAL, s.Field) + } +} + +type taggedSubStruct struct { + SubStruct struct { + Field string + } `env:"POTATOE"` +} + +func TestTaggedSubStruct(t *testing.T) { + const ENV_KEY = "POTATOE_FIELD" + const ENV_VAL = "Remember: testing is the future!" + + os.Clearenv() + os.Setenv(ENV_KEY, ENV_VAL) + + s := taggedSubStruct{} + + ReadInto(&s) + + if s.SubStruct.Field != ENV_VAL { + t.Errorf("expected '%s', got '%s'", ENV_VAL, s.SubStruct.Field) + } +} + +type absTaggedField struct { + SubStruct struct { + Field string `env:"POTATOE" absenv:"true"` + } +} + +func TestAbsTaggedField(t *testing.T) { + const ENV_KEY = "POTATOE" + const ENV_VAL = "Remember: testing is the future!" + + os.Clearenv() + os.Setenv(ENV_KEY, ENV_VAL) + + s := absTaggedField{} + + ReadInto(&s) + + if s.SubStruct.Field != ENV_VAL { + t.Errorf("expected '%s', got '%s'", ENV_VAL, s.SubStruct.Field) + } +} -- cgit v1.2.3