-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotenv_test.go
73 lines (68 loc) · 1.54 KB
/
dotenv_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package dotenv
import (
"os"
"testing"
)
func TestSetEnv(t *testing.T) {
key := "test"
value := "value"
SetEnv(key, value)
expected := os.Getenv("test")
got := os.Getenv("test")
if expected != got {
t.Errorf("dotenv.SetEnv(%s, %s) returned %s, expected %s", key, value, got, expected)
}
}
func TestGetEnv(t *testing.T) {
os.Setenv("test", "value")
value := "test"
expected := os.Getenv("test")
got := GetEnv("test")
if expected != got {
t.Errorf("dotenv.GetEnv(%s) returned %s, expected %s", value, got, expected)
}
}
func TestLoadFile(t *testing.T) {
err := os.Setenv("Test", "othervalue")
if err != nil {
return
}
err = LoadFile("/testdotenv/test.env")
if err != nil {
return
}
expected1 := "othervalue"
expected2 := GetEnv("Test1")
got1 := GetEnv("Test")
got2 := GetEnv("Test1")
if expected1 != got1 {
t.Errorf("dotenv.GetEnv() returned %s, expected %s", got1, expected1)
}
if expected2 != got2 {
t.Errorf("dotenv.GetEnv() returned %s, expected %s", got1, expected2)
}
}
func TestOverloadFile(t *testing.T) {
err := os.Setenv("Test", "othervalue")
if err != nil {
return
}
err = os.Setenv("Test1", "othervalue1")
if err != nil {
return
}
err = OverloadFile("/testdotenv/test.env")
if err != nil {
return
}
expected1 := "testvalue"
expected2 := "testvalue1"
got1 := GetEnv("Test")
got2 := GetEnv("Test1")
if expected1 != got1 {
t.Errorf("dotenv.GetEnv() returned %s, expected %s", got1, expected1)
}
if expected2 != got2 {
t.Errorf("dotenv.GetEnv() returned %s, expected %s", got2, expected2)
}
}