generated from sv-tools/go-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_test.go
45 lines (34 loc) · 879 Bytes
/
reader_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
package confenv_test
import (
"context"
"fmt"
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/sv-tools/conf"
confenv "github.com/sv-tools/conf-reader-env"
)
const envName = "TEST_FOO"
func TestNew(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, os.Unsetenv(envName))
})
require.NoError(t, os.Setenv(envName, "42"))
c := conf.New().WithReaders(confenv.New(map[string]string{envName: "foo"}, ""))
require.NoError(t, c.Load(context.Background()))
require.Equal(t, 42, c.GetInt("foo"))
}
func ExampleNew() {
if err := os.Setenv(envName, "42"); err != nil {
panic(err)
}
c := conf.New().WithReaders(confenv.New(map[string]string{envName: "foo"}, ""))
if err := c.Load(context.Background()); err != nil {
panic(err)
}
fmt.Println(c.GetInt("foo"))
// Output: 42
if err := os.Unsetenv(envName); err != nil {
panic(err)
}
}