-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotenv_test.go
58 lines (49 loc) · 1.02 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
package dotenv
import (
"os"
"testing"
)
type Var struct {
Name string
Value string
}
func Test_Load_ExpectVarsLoadedSuccessfully(t *testing.T) {
os.Clearenv()
err := Load(".env.test")
if err != nil {
t.Errorf("Expected no error parsing but found %s", err)
}
multiline, _ := os.ReadFile("multiline.test")
var expectedVars = []Var{
{
Name: "TEST_VAR",
Value: "test-value",
},
{
Name: "test_var_quotes",
Value: "test-value-quotes",
},
{
Name: "TEST_VAR_SPACES",
Value: " does not trim spaces ",
},
{
Name: "TEST_MULTI_LINE",
Value: string(multiline),
},
{
Name: "TEST_SINGLE_QUOTE",
Value: "test single quotes",
},
{
Name: "TEST_SINGLE_QUOTE_WITH_DOUBLE_QUOTE",
Value: "\"\"",
},
}
for i := 0; i < len(expectedVars); i++ {
var actualValue = os.Getenv(expectedVars[i].Name)
if actualValue != expectedVars[i].Value {
t.Errorf("Expected var %s to be %v but found %v", expectedVars[i].Name, []byte(expectedVars[i].Value), []byte(actualValue))
}
}
}