-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_int_test.go
51 lines (45 loc) · 1.09 KB
/
parser_int_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_parseInt_Valid_WithPrefix(t *testing.T) {
os.Setenv("ACME_INT", "123")
defer os.Unsetenv("ACME_INT")
var v int
p, err := NewParserWithName(&v, "ACME", "_", "INT", NoConv)
if err != nil {
t.Fatalf("newParser: %#v", err)
}
if err := p.parseInt(); err != nil {
t.Fatalf("parseInt said: %#v", err)
}
if v != 123 {
t.Fatalf("failed to recover value")
}
}
func Test_Parser_parseInt_Valid_WithoutPrefix(t *testing.T) {
os.Setenv("INT", "123")
defer os.Unsetenv("INT")
var v int
p, err := NewParserWithName(&v, "", "_", "INT", NoConv)
if err != nil {
t.Fatalf("newParser: %#v", err)
}
if err := p.parseInt(); err != nil {
t.Fatalf("parseInt said: %#v", err)
}
if v != 123 {
t.Fatalf("failed to recover value")
}
}
func Test_Parser_parseInt_InValid(t *testing.T) {
var v int
p, err := NewParserWithName(&v, "", "_", "ACME_FOO_THIS_VAR_SHOULD_NOT_EXIST", NoConv)
if err != nil {
t.Fatalf("newParser: %#v", err)
}
if err := p.parseInt(); err == nil {
t.Fatal("parseInt didn't error on non existing env var", err)
}
}