-
Notifications
You must be signed in to change notification settings - Fork 2
/
env_test.go
68 lines (62 loc) · 1.66 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package nfigure
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestEnvArrayPtr1(t *testing.T) {
require.NoError(t, os.Setenv("X", "382:32"), "set X")
var testData struct {
X *[]int `env:"X,split=:"`
}
registry := NewRegistry()
require.NoError(t, registry.Request(&testData), "add model")
err := registry.Configure()
require.NoError(t, err, "configure")
want := []int{382, 32}
assert.Equal(t, &want, testData.X, "X")
}
func TestEnvArrayPtr2(t *testing.T) {
require.NoError(t, os.Setenv("X", "382:32"), "set X")
var testData struct {
X **[]int `env:"X,split=:"`
}
registry := NewRegistry()
require.NoError(t, registry.Request(&testData), "add model")
err := registry.Configure()
require.NoError(t, err, "configure")
want := []int{382, 32}
assert.Equal(t, &want, *testData.X, "X")
}
func TestEnvArrayPtr3(t *testing.T) {
require.NoError(t, os.Setenv("X", "382:32"), "set X")
var testData struct {
X ***[]int `env:"X,split=:"`
}
registry := NewRegistry()
require.NoError(t, registry.Request(&testData), "add model")
err := registry.Configure()
require.NoError(t, err, "configure")
want := []int{382, 32}
assert.Equal(t, &want, **testData.X, "X")
}
func TestEnvStruct(t *testing.T) {
require.NoError(t, os.Setenv("X", `{"Y":3,"Z":"foo"}`), "set X")
type innerStruct struct {
Y int
Z string
}
var testData struct {
X *innerStruct `env:"X,JSON"`
}
registry := NewRegistry()
require.NoError(t, registry.Request(&testData), "add model")
err := registry.Configure()
require.NoError(t, err, "configure")
want := &innerStruct{
Y: 3,
Z: "foo",
}
assert.Equal(t, want, testData.X, "X")
}