MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / TestSanitizeJSONKeys

Function TestSanitizeJSONKeys

plugins/destination/s3/client/write_test.go:40–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestSanitizeJSONKeys(t *testing.T) {
41 m := map[string]any{
42 "foo": "bar",
43 "bar": map[string]any{
44 "foo-bar": "baz",
45 },
46 "foo:bar": "baz",
47 "foo-bar-baz": []any{"baz", map[string]any{"foo:bar": "baz"}},
48 "string": map[string]string{
49 "foo-bar": "baz",
50 },
51 "int": map[string]int{
52 "foo-bar": 123,
53 },
54 "pointer": map[string]*string{
55 "foo-bar": &[]string{"baz"}[0],
56 },
57 }
58
59 bytes, err := json.Marshal(m)
60 require.NoError(t, err)
61 var data any
62 require.NoError(t, json.Unmarshal(bytes, &data))
63
64 sanitized := sanitizeJSONKeysForObject(data)
65 want := map[string]any{
66 "foo": "bar",
67 "bar": map[string]any{
68 "foo_bar": "baz",
69 },
70 "foo_bar": "baz",
71 "foo_bar_baz": []any{"baz", map[string]any{"foo_bar": "baz"}},
72 "string": map[string]any{
73 "foo_bar": "baz",
74 },
75 "int": map[string]any{
76 "foo_bar": 123.0,
77 },
78 "pointer": map[string]any{
79 "foo_bar": "baz",
80 },
81 }
82 if diff := cmp.Diff(want, sanitized); diff != "" {
83 t.Errorf("sanitizeJSONKeys() mismatch (-want +got):\n%s", diff)
84 }
85}
86
87func TestReplacePathVariables(t *testing.T) {
88 cases := []struct {

Callers

nothing calls this directly

Calls 2

ErrorfMethod · 0.80

Tested by

no test coverage detected