aboutsummaryrefslogtreecommitdiff
path: root/typeconv_test.go
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-02-14 11:24:17 +0100
committerPacien TRAN-GIRARD2015-02-14 11:27:36 +0100
commit8e99baedf2c3e433750c2f51681f3c9d15d412be (patch)
tree3fa0ff3ea4823a408dadceb14fcd51ddc16c2aa8 /typeconv_test.go
parent8b1f88ce72ef8496879395e7f04b676e6a16e07a (diff)
downloadgo-envcfg-8e99baedf2c3e433750c2f51681f3c9d15d412be.tar.gz
First version
Diffstat (limited to 'typeconv_test.go')
-rw-r--r--typeconv_test.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/typeconv_test.go b/typeconv_test.go
new file mode 100644
index 0000000..c851b5b
--- /dev/null
+++ b/typeconv_test.go
@@ -0,0 +1,71 @@
1package envcfg
2
3import (
4 "fmt"
5 "os"
6 "testing"
7)
8
9func TestStringMapping(t *testing.T) {
10 const ENV_KEY = "FIELD"
11 const ENV_VAL = "Remember: testing is the future!"
12
13 os.Clearenv()
14 os.Setenv(ENV_KEY, ENV_VAL)
15
16 s := struct{ Field string }{}
17
18 ReadInto(&s)
19
20 if s.Field != ENV_VAL {
21 t.Errorf("expected '%s', got '%s'", ENV_VAL, s.Field)
22 }
23}
24
25func TestBoolMapping(t *testing.T) {
26 const ENV_KEY = "FIELD"
27 const ENV_VAL = true
28
29 os.Clearenv()
30 os.Setenv(ENV_KEY, fmt.Sprintf("%t", ENV_VAL))
31
32 s := struct{ Field bool }{}
33
34 ReadInto(&s)
35
36 if s.Field != ENV_VAL {
37 t.Errorf("expected '%t', got '%t'", ENV_VAL, s.Field)
38 }
39}
40
41func TestIntMapping(t *testing.T) {
42 const ENV_KEY = "FIELD"
43 const ENV_VAL = 42
44
45 os.Clearenv()
46 os.Setenv(ENV_KEY, fmt.Sprintf("%d", ENV_VAL))
47
48 s := struct{ Field int }{}
49
50 ReadInto(&s)
51
52 if s.Field != ENV_VAL {
53 t.Errorf("expected '%d', got '%d'", ENV_VAL, s.Field)
54 }
55}
56
57func TestFloatMapping(t *testing.T) {
58 const ENV_KEY = "FIELD"
59 const ENV_VAL = 13.37
60
61 os.Clearenv()
62 os.Setenv(ENV_KEY, fmt.Sprintf("%f", ENV_VAL))
63
64 s := struct{ Field float32 }{}
65
66 ReadInto(&s)
67
68 if s.Field != ENV_VAL {
69 t.Errorf("expected '%f', got '%f'", ENV_VAL, s.Field)
70 }
71}