forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonparserw_test.go
37 lines (27 loc) · 1.02 KB
/
jsonparserw_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
package jsonparserw
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestHappyPath(t *testing.T) {
jsonBlob := []byte("{\"foo\": 1, \"bar\": true, \"baz\": \"bing\"}")
foo, err := GetInt(jsonBlob, "foo")
require.NoError(t, err)
require.Equal(t, foo, int64(1))
bar, err := GetBoolean(jsonBlob, "bar")
require.NoError(t, err)
require.Equal(t, bar, true)
baz, err := GetString(jsonBlob, "baz")
require.NoError(t, err)
require.Equal(t, baz, "bing")
}
func TestDescriptiveErrorMessage(t *testing.T) {
jsonBlob := []byte("{\"raimbaut\": \"roussillon\", \"bradamante\": \"aedificium\"}")
_, err := GetString(jsonBlob, "agilulf", "bertrandin", "guildivern", "corbentraz")
// Should not include data to avoid leaking sensitive information in log sends
require.NotContains(t, err.Error(), "raimbaut")
// Should include keys
require.Contains(t, err.Error(), "with keys [agilulf bertrandin guildivern corbentraz]")
// Should include original error message
require.Contains(t, err.Error(), "Key path not found")
}