-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
env_test.go
46 lines (36 loc) · 1.05 KB
/
env_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
package main
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestNewEnv(t *testing.T) {
t.Run("Env present", func(t *testing.T) {
defer os.Unsetenv("MY_AWESOME_ENV")
os.Setenv("MY_AWESOME_ENV", "some-content")
_, err := NewEnv([]string{"MY_AWESOME_ENV"})
assert.Empty(t, err)
})
t.Run("Env missing", func(t *testing.T) {
_, err := NewEnv([]string{"MY_AWESOME_ENV"})
assert.Errorf(t, err, "missing %s in environment variable", "MY_AWESOME_ENV")
})
}
func TestEnv_Get(t *testing.T) {
t.Run("Env present", func(t *testing.T) {
defer os.Unsetenv("MY_AWESOME_ENV")
os.Setenv("MY_AWESOME_ENV", "some-content")
env, err := NewEnv([]string{"MY_AWESOME_ENV"})
assert.Empty(t, err)
assert.Equal(t, "some-content", env.Get("MY_AWESOME_ENV"))
})
t.Run("Env missing", func(t *testing.T) {
defer os.Unsetenv("MY_AWESOME_ENV")
os.Setenv("MY_AWESOME_ENV", "some-content")
env, err := NewEnv([]string{"MY_AWESOME_ENV"})
assert.Empty(t, err)
assert.Panics(t, func() {
_ = env.Get("ANOTHER_AWESOME_ENV")
})
})
}