forked from ory/kratos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_json_test.go
54 lines (46 loc) · 1.73 KB
/
map_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
44
45
46
47
48
49
50
51
52
53
54
package x
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTypeMap(t *testing.T) {
r, err := TypeMap(map[string]string{
"string": "string",
"int": "123",
"float": "123.123",
"bool": "TrUe",
"bool_on": "oN",
})
require.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"string": "string",
"int": int64(123),
"float": 123.123,
"bool": true,
"bool_on": true,
}, r)
_, err = TypeMap(map[string]string{
"int": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
})
assert.Error(t, err)
_, err = TypeMap(map[string]string{
"float": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.9",
})
assert.Error(t, err)
}
func TestUntypedMapToJSON(t *testing.T) {
r, err := UntypedMapToJSON(map[string]string{
"string": "string",
"int": "123",
"float": "123.123",
"bool": "TrUe",
"bool_on": "oN",
})
require.NoError(t, err)
assert.JSONEq(t, `{"string":"string","int":123,"float":123.123,"bool":true,"bool_on":true}`, string(r))
_, err = UntypedMapToJSON(map[string]string{
"int": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
})
assert.Error(t, err)
}