-
Notifications
You must be signed in to change notification settings - Fork 11
/
dotenv_internal_test.go
90 lines (73 loc) · 2.08 KB
/
dotenv_internal_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package dotenv
import (
"log"
"os"
"testing"
"github.com/stretchr/testify/require"
)
const k6env = "K6_ENV"
//nolint:forbidigo
func TestMain(m *testing.M) {
if err := os.Chdir("testdata"); err != nil {
log.Fatal(err)
}
os.Exit(m.Run())
}
//nolint:forbidigo
func unset(t *testing.T) {
t.Helper()
require.Nil(t, os.Unsetenv("global"))
require.Nil(t, os.Unsetenv("common"))
require.Nil(t, os.Unsetenv("local"))
require.Nil(t, os.Unsetenv("localonly"))
}
//nolint:forbidigo
func Test_default(t *testing.T) { //nolint:paralleltest
t.Setenv(k6env, "")
unset(t)
load()
require.Equal(t, ".env", os.Getenv("global"))
require.Equal(t, ".env.development", os.Getenv("common"))
require.Equal(t, ".env.development.local", os.Getenv("local"))
require.Equal(t, ".env.local", os.Getenv("localonly"))
}
//nolint:forbidigo
func Test_disabled(t *testing.T) { //nolint:paralleltest
t.Setenv(k6env, "false")
unset(t)
load()
require.Empty(t, os.Getenv("global"))
require.Empty(t, os.Getenv("common"))
require.Empty(t, os.Getenv("local"))
require.Empty(t, os.Getenv("localonly"))
}
//nolint:forbidigo
func Test_test(t *testing.T) { //nolint:paralleltest
t.Setenv(k6env, "test")
unset(t)
load()
require.Equal(t, ".env", os.Getenv("global"))
require.Equal(t, ".env.test", os.Getenv("common"))
require.Equal(t, ".env.test.local", os.Getenv("local"))
require.Empty(t, os.Getenv("localonly"))
}
//nolint:forbidigo
func Test_production(t *testing.T) { //nolint:paralleltest
t.Setenv(k6env, "production")
unset(t)
load()
require.Equal(t, ".env", os.Getenv("global"))
require.Equal(t, ".env.production", os.Getenv("common"))
require.Equal(t, ".env.production.local", os.Getenv("local"))
require.Equal(t, ".env.local", os.Getenv("localonly"))
}
//nolint:forbidigo
func Test_development(t *testing.T) { //nolint:paralleltest
t.Setenv(k6env, "development")
unset(t)
load()
require.Equal(t, ".env", os.Getenv("global"))
require.Equal(t, ".env.development", os.Getenv("common"))
require.Equal(t, ".env.development.local", os.Getenv("local"))
require.Equal(t, ".env.local", os.Getenv("localonly"))
}