-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_float_test.go
51 lines (45 loc) · 1.14 KB
/
parser_float_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package envcnf
import (
"os"
"testing"
)
func Test_Parser_parseFloat_Valid_WithPrefix(t *testing.T) {
os.Setenv("ACME_FLOAT", "123.45")
defer os.Unsetenv("ACME_FLOAT")
var v float64
p, err := NewParserWithName(&v, "ACME", "_", "FLOAT", NoConv)
if err != nil {
t.Fatalf("newParser: %#v", err)
}
if err := p.parseFloat(); err != nil {
t.Fatalf("parseFloat said: %#v", err)
}
if v != 123.45 {
t.Fatalf("failed to recover value")
}
}
func Test_Parser_parseFloat_Valid_WithoutPrefix(t *testing.T) {
os.Setenv("FLOAT", "123.45")
defer os.Unsetenv("FLOAT")
var v float64
p, err := NewParserWithName(&v, "", "_", "FLOAT", NoConv)
if err != nil {
t.Fatalf("newParser: %#v", err)
}
if err := p.parseFloat(); err != nil {
t.Fatalf("parseFloat said: %#v", err)
}
if v != 123.45 {
t.Fatalf("failed to recover value")
}
}
func Test_Parser_parseFloat_InValid(t *testing.T) {
var v float64
p, err := NewParserWithName(&v, "", "_", "ACME_FOO_THIS_VAR_SHOULD_NOT_EXIST", NoConv)
if err != nil {
t.Fatalf("newParser: %#v", err)
}
if err := p.parseFloat(); err == nil {
t.Fatal("parseFloat didn't error on non existing env var", err)
}
}