-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetenv_test.go
44 lines (37 loc) · 958 Bytes
/
getenv_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
package getenv
import (
"testing"
"reflect"
)
func TestGetEnv(t *testing.T) {
env := GetEnv("TEST_STR_ENV", "NG")
envType := reflect.TypeOf(env)
if envType.String() != "*getenv.envstr" {
t.Errorf("Type mismatch: %s", envType.String())
}
t.Logf("Ok: %s", envType)
}
func TestEnvstr_String(t *testing.T) {
str := GetEnv("TEST_STR_ENV", "NG").String()
if str != "hello" {
t.Errorf("Failed to get env with key: %s, result: %s", "TEST_STR_ENV", str)
return
}
t.Logf("Ok: %s", str)
}
func TestEnvstr_Int(t *testing.T) {
intval := GetEnv("TEST_INT_ENV", "0").Int()
if intval != 128 {
t.Errorf("Failed to get env with key: %s, result: %d", "TEST_INT_ENV", intval)
return
}
t.Logf("Ok: %d", intval)
}
func TestEnvstr_Bool(t *testing.T) {
boolval := GetEnv("TEST_BOOL_ENV", "false").Bool()
if boolval != true {
t.Errorf("Failed to get env with key: %s, result: %d", "TEST_BOOL_ENV", boolval)
return
}
t.Logf("Ok: %v", boolval)
}