-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_test.go
43 lines (37 loc) · 915 Bytes
/
json_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
package lflag
import (
"bytes"
. "testing"
"github.com/stretchr/testify/assert"
)
func TestSourceJSON(t *T) {
pp := []Param{
{ParamType: ParamTypeString, Name: "str"},
{ParamType: ParamTypeString, Name: "str2"},
{ParamType: ParamTypeInt, Name: "int"},
{ParamType: ParamTypeBool, Name: "bool"},
{ParamType: ParamTypeDuration, Name: "dur"},
{ParamType: ParamTypeJSON, Name: "json"},
}
ts := SourceStub{
"str2": "bar", // this should overwrite the one in the jsonFile
}
jsonFile := bytes.NewBufferString(`{
"str": "foo\nsomething",
"str2": "broken",
"int": 1,
"bool": true,
"dur": "30s",
"json": {"foo":"bar"}
}`)
m, err := sourceJSON{innerSrc: ts, testJSONFile: jsonFile}.Parse(pp)
assert.NoError(t, err)
assert.Equal(t, map[string]string{
"str": "foo\nsomething",
"str2": "bar",
"int": "1",
"bool": "true",
"dur": "30s",
"json": `{"foo":"bar"}`,
}, m)
}