Skip to content

Commit fdcc6b4

Browse files
author
Mohammed Ehab
committed
More tests
1 parent f9b3690 commit fdcc6b4

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

lambdacontext/context_test.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,31 @@ import (
55
"testing"
66

77
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
89
)
910

10-
func TestClientContextUnmarshalJSON_InvalidJSON(t *testing.T) {
11-
var cc ClientContext
12-
err := json.Unmarshal([]byte(`not valid json`), &cc)
13-
assert.Error(t, err)
14-
assert.Empty(t, cc.Custom)
11+
func TestClientContextUnmarshalJSON(t *testing.T) {
12+
t.Run("non-string custom values are serialized to string", func(t *testing.T) {
13+
input := `{
14+
"Client": {"installation_id": "install1"},
15+
"custom": {
16+
"key1": "stringval",
17+
"key2": {"nested": "object"},
18+
"key3": 42
19+
}
20+
}`
21+
var cc ClientContext
22+
err := json.Unmarshal([]byte(input), &cc)
23+
require.NoError(t, err)
24+
assert.Equal(t, "install1", cc.Client.InstallationID)
25+
assert.Equal(t, "stringval", cc.Custom["key1"])
26+
assert.JSONEq(t, `{"nested":"object"}`, cc.Custom["key2"])
27+
assert.Equal(t, "42", cc.Custom["key3"])
28+
})
29+
30+
t.Run("invalid JSON returns error", func(t *testing.T) {
31+
var cc ClientContext
32+
err := json.Unmarshal([]byte(`not valid json`), &cc)
33+
assert.Error(t, err)
34+
})
1535
}

0 commit comments

Comments
 (0)